I need to upload a file as body with PUT request to server of Content-Type:application/octet-stream .
I have searched a lot and all the examples consists of multipart but none of it contains how to put the byte to server.
Can someone help me out?
You should use multipart request in order to upload a file using Volley. You can implement your own functions or use a ready library. Here is a good one I used in a project before multipart-android
Related
I want to upload a video file from IOS/Android client to RAILS JSON api server.
I am trying this from a rails api only application. For image uploading i used to encode image in base64 format and pass this Base64 value as a JSON param. But if i use the same logic, it is not practical for a large file, say for 10MB or 20MB.
Any help would be much appreciated. Thanks for the help in advance.
It's actually a valid option to upload the file encoded in Base64 for a normal JSON-API request. You can decode the String in the Rails controller roughly with the following code:
def upload_action_method
file = StringIO.new(Base64.decode(params[:file_data])
end
The disadvantage of this approach is how you already recognized the increased filesize of roughly ~33%.
The other way would be to perform a multi-part/form-data POST request from the IOS or Android device. This way, Rails should get access for the File object in the params hash, just like a normal file upload form. You need to build a valid request for the native device manually or use a existing library. I referenced you 2 other answers showing code examples for building a multipart request:
Android: Android- POST multipart form data
IOS: Upload image with parameters in Swift
Recently I have been working on an app and it requires the files on the phone to be uploaded to the server. These file may be either images or videos. I used ASyncTask to do the networking on the background.
However if the file size is greater than 45 MBs the file upload fails...it works just fine other-wise
What should I use instead of Async Tasks? Should I go for Sync Adapters or for the Volley library? I know nothing in either of these.
You can use retrofit typedfile approach to upload file in multi-part.
For your reference :
https://futurestud.io/blog/retrofit-how-to-upload-files/
What response do you get from the server when the upload fails? Understanding the response can help you get insight into why the upload is failing. One possibility is that the server you are trying to upload file to is not configured to handle that big payload in which case you will get the following HTTP response.
HTTP Error 413 Request entity too large
HTTP Error 413
However this is just one of the possibilities. I suggest you to inspect HTTP response and it's other properties.
Why or when should someone use Multipart/form-data?
the thing is I use to upload images to server with httpost base64 (random example) but I noticed while reading through volley I Can upload file with multipart/form-data ..
So when should I use consider to upload my images to server ? multipart or httpost base64
Multipart is multi part (duh).
So if you have a very large file the request will send it in multiple parts instead of inside a "regular" POST request. Since POST requests also have an upper limit, which now I don't remember but its not that much (a couple of megabytes) if you upload something huge you should use multipart-forms if you use http.
Please share, if its possible to post an image to web server without using MultipartEntity class.
Previously, i followed this tutorial https://vikaskanani.wordpress.com/2011/01/29/android-image-upload-activity/ for post an image in server. May i know possible ways to post image other than this method.
If you use HttpURLConnection you can directly write your data to the output stream.
After countless headaches and time wasted I managed to get the AudioRecorder working for Android and have a file stored on my SDcard. What I want to do now is send this file to a server within the application. So when the user hits submit...it sends the .3gp file. Is this possible? Thanks
I'd recommend that you just use HTTP and POST it to your server.
Here's a good little code snippet that shows how to do an HTTP post from java.
http://rapidandroid.org/wiki/HttpUpload
Then you'll have to receive the file on your server. You could just use a simple php script for that unless you have some other server side technology.
Here's some documentation for doing this using php:
http://www.tizag.com/phpT/fileupload.php
yes you should use FTP because it will be faster...
I had done bit R&D on it and found few link but most of them were not working.
here is the link that is working for FTP upload..
http://www.jibble.org/simpleftp/