How can I upload a file from an external service or app (iOS App, Go App, etc) to a Rails REST API which uses Active Storage local file storage?
All the tutorials I can find use HTML forms. I'd like to upload my files via a POST request to the Rails API. The main thing I am uncertain about is what headers and what kind of format I need to send the files in to the backend.
The solution was to just send normal form-data. I used Postman for testing which works great for file uploads as well http://getpostman.com
Base64 is useful for you, You can decode base64 then generate temp file and upload that file.
Related
My goal is essentially to upload a video file, like this, but with Ruby on Rails instead of PHP. I can successfully send JSON data to my server, but haven't been able to get file uploads working. The end objective is to have the file be in the server's /tmp directory, just like files uploaded via a webpage file_field_tag.
This image:
shows what I've tried so far. The result is that on the server, the parameter list is empty, unlike if you had used a file_field_tag. In the PHP example, they are able to get the contents of the file from the input stream... maybe there is something similar in Rails?
I know my API works, as I was able to successfully make a request using a JavaScript XMLHttpRequest, so I'm led to believe the solution involves working around what App Inventor offers for HTTP requests.
Edit: Removed unsupported header since the PHP example doesn't use headers anyways
I want to upload large files on S3. I know there is an option multipart upload by which I can upload large file in parts. I read the documentation (http://docs.aws.amazon.com/mobile/sdkforios/developerguide/s3transfermanager.html) but didn't find any code for the multipart upload. I have successfully uploaded a file on server as a single file but I want to use multipart for large file.
Thanks.
IF you're still looking for a solution, you can check out my blog post on this subject: Taming the AWS framework to upload a large file to S3. For large files you will have to skip using the AWSTransferManager as it uses cognito credentials which are limited to an hour validity.
My website generates a file in javascript (audio recording) and I then want it to be uploaded to Amazon S3.
I first managed to get the uploading part working by sending the generated file to my server, where it is uploaded. However I would like now to upload the file directly to S3, without going through my server.
So I started to use the s3_direct_upload gem, which works great when using a file_field. However my file is generated by the javascript and :
- The value of a file field has to be set by the user for security reasons
- I do not want the user to have to interact with the upload
I tried to play with the S3Uploader class and to directly add data, without any success for now, it seems that I do not use the correct method.
Does anyone has any idea on how to achieve S3 direct upload without a file field ?
Thanks
Never mind, I found out that the S3Uploader class used by the s3_direct_upload gem has the same methods as the jQuery-File-Upload from which it is derived.
So one can call $("#s3_uploader").fileupload('send', {files: [f]});
And the f File will be uploaded to S3 directly
I'm writing an importation function from a remote service to our app which uses S3. I connect to an api using OAuth as authentication, so every request I make I need to attach the token in the header. The attachments must be copied to S3 and the model is using paperclip.
I read the file from the api (say origin) with a GET method which returns a response with the body filled in with the content and the header with filename and other information.
Q: Now that I have the body of the file in plain text, how do I store it in S3 (destination) with paperclip?
Alternatively
Q: I could upload the file to S3 (destination) using remote URL(as described here), but how do I attach the token to the paperclip request to the (origin) api?
thanks
You need to create an s3.yml in your config directory... Here's a detailed tutorial in setting up paper clip with rails 3: http://doganberktas.com/2010/09/14/amazon-s3-and-paperclip-rails-3/
I would suggest you use a conversion tool to generate either a PDF or an editable document, then upload that to s3... Here's a good PDF gem: http://ruby-pdf.rubyforge.org/pdf-writer/ and even a railscast to help: http://railscasts.com/episodes/78-generating-pdf-documents
and here's an rtf gem: https://rubygems.org/gems/rtf
Since you have the raw data that should work.
I have a web service in Rails which among all else should provide file upload functionality to the clients. The clients all use JSON to talk to the webservice. I use the Paperclip plugin for upload management.
The problem is I do not know how to upload a file via JSON. All works in the web formular, but I cannot find information on how to consctruct my JSON Request to send files to the server. Can somebody help out?
Regards,
Angel Kafazov
You don't need to use Paperclip for uploading JSON files in rails. Use the following syntax inserting the file upload field to your view. To read the JSON files in your controllers, import JSON package to read the contents.
<%= file_field 'LABEL', 'QUERY_PARAMETER_NAME' %></p>
I didn't try this yet, but this looks promising:
http://leejava.wordpress.com/2009/07/30/upload-file-from-rest-in-ruy-on-rail-with-json-format/