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
Related
I'm migrating from PHP 5+ to PHP 7+ on standard app engine.
To upload file, I'm making a POST request to an internal endpoint with all form data (text and file to upload).
Actually what I was doing on v5 to let this work:
Get the URL with CloudStorageTools::createUploadUrl
POST everything to the url returned from the step before
In this way, all posted form (text and file to upload) was posted correctly to my internal endpoint and file can be uploaded on google storage.
Migrating to php 7+ CloudStorageTools::createUploadUrl can't be used.
Direcly upload working fine, if file is not so bigger.
For bigger file I haven't still found a solution, a lot of people have this problem but seems no one actually solved it.
There is some workaround or some tips to solve it?
I've already tested different methods got from here: https://googleapis.github.io/google-cloud-php/#/docs/cloud-storage/v1.23.2/storage/readme
No one is actually working (I got URL where upload, but at the end of upload everything crash).
Google documentation about that is not so clear, they say you can't use the older library, but actually online I can find always the same basically code that it's not good for larger file.
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.
There is a lot of information in the title of the question !
I'm aware of Rails gems to upload files, parse Excel, etc. but I would like to know which solution will work nice in a Backbone app (that is, I don't want to reload the page during the upload). Is there a Backbone extension for that ?
The story is: the user wants to upload an Excel file, she browses her filesystem, selects the file, click "upload"... and then the Backbone app shows the content of the file (I don't need to store the file on the server).
Well, i dont think there is any backbone extension for that :) What you need is some upload extension like uploadify of http://blueimp.github.com/jQuery-File-Upload/ . You will bind the
success method to uploader and then you can do anything with the data returned from server.
I'm writing a Rails application that serves files stored on a remote server to the end user.
In my case the files are stored on S3 but the user requests the file via the Rails-application (hiding the actual URL). If the file was on my servers local file-system, I could use the Apache header X-Sendfile to free up the Ruby process for other requests while Apache took over the task of sending the file to the client. But in my case - where the file is not on the local file-system, but on S3 - it seems that I'm forced to download it temporarily inside Rails before sending it to the client.
Isn't there a way for Apache to serve a "remote" file to the client that is not actually on the server it self. I don't mind if Apache has to download the file for this to work, as long as I don't have to tie up the Ruby process while it's going on.
Any suggestions?
Thomas, I have similar requirements/issues and I think I can answer your problem. First (and I'm not 100% sure you care for this part), hiding the S3 url is quite easy as Amazon allows you to point CNAMES to your bucket and use a custom URL instead of the amazon URL. To do that, you need to point your DNS to the correct amazon URL. When I set mine up it was similar to this: files.domain.com points to files.domain.com.s3.amazonaws.com. Then you need to create the bucket with the name of your custom URL (files.domain.com in this example). How to call that URL will be different depending on which gem you use, but a word of warning was that the attachment_fu plugin I was using was incorrectly sending me to files.domain.com/files.domain.com/name_of_file.... I couldn't find the setting to fix it, so a simple .sub method for the S3 portion of the plugin fixed it.
On to your other questions, to execute some rails code (like recording the hit in the db) before downloading you can simply do this:
def download
file = File.find(...
# code to record 'hit' to database
redirect_to 3Object.url_for(file.filename,
bucket,
:expires_in => 3.hours)
end
That code will still cause the file to be served by S3, but and still give you the ability to run some ruby. (Of course the above code won't work as is, you will need to point it to the correct file and bucket and my amazon keys are saved in a config file. The above is also using the syntax for the AWS::S3 gem - http://amazon.rubyforge.org/).
Second, the Content-Disposition: attachment issue is a bit more tricky. Hopefully, your situation is a bit more simple than mine and the following solution can work. Assuming the object 'file' (in this example) is the correct S3 object, you can set the disposition to attachment by
file.content_disposition = "attachment"
file.save
The above code can be executed after the file exists on the S3 server (unlike some other headers and permissions), which is nice and it can also be added when you upload the file (syntax depends on your plugin). I'm still trying to find a way to tell S3 to send it as an attachment and only when requested (not every time), and if you find that, please let me know your solution. I need to be able to sometimes download it and other times save embed images (for example) into HTML. I'm not using the above mentioned redirect but fortunately it seems that if you embed (such as a HTML image tag) a file with the content-disposition/attachment header, and the browser still displays the image normally (but I haven't throughly tested that across enough browsers to send it in the wild).
Hope that helps! Good luck.
I have a Rails application setup to receive file attachments using Paperclip.
Now I need to allow a .net/C# cell phone application to post files along with the XML in the same way (or some other way if necessary: they could encode the image as base64 and send - they tried that initially - including the binary data in the tag that would normally be a file field in the web application, but it did not work.
I have found nothing in the way of documentation and wondering if anybody has experience or advice.
Surprising that there is apparently no documentation for doing this anywhere to be found. I ended up stumbling across a document on the Basecamp website describing how their file attachment process works for API users and used it as a guideline.
http://developer.37signals.com/basecamp/
with help from this article about posting files:
http://www.codevil.com/index.php/2009/05/23/posting-and-getting-files-in-rubyrails/
I modified my initial setup so that, rather than passing the tag in the XML, they first post a file and receive an file ID in response.
Then they post the XML with that reference and their .
Then I use before_validation and after_save callbacks to set the file with Paperclip, and remove the tmp file after the save.