How can we upload a video file using REST API in Rails - android

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

Related

How to upload a large file on android?

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.

uploading files directly to server without web service from android

ok so i need to upload files directly to server without using any web service from android ..
first i am doing so with REST web service but the thing is it always say transaction is too large when executing my request .... in android i convert the image into byte[] then into Base64 string from my server side i decode this Base64 string and write bytes into file.
how can i upload directly to folder on my server ... something like executing a function that upload the file to "localhost/myWebApplicationDir/images/"then file here.jpg"
You will need to implement something that handles uploads as webservers typically don't do that out of the box. I'm sure you can find a POST upload script written in PHP somewhere on google. Then implement some code that POSTs the file to the endpoint and you should be fine.
There are no out-of-the-box tools for this but it's not a lot of work.
i found this link to be very helpful i discovered that you need an open connection with the server and communicate with streams something like keeping connection alive and upload files bit by bit.... but still you need a web service like #meredrica said.
http://ihofmann.wordpress.com/2013/01/23/android-sending-post-requests-with-parameters/

How to send image from one device to another in background on Android?

I need a workaround for the following task:
I have a JPG (of whatever) picture on my sd card, and I need to send it to another device in the background. How should I do that?
Best way (in theory) would be via MMS, but after a lof of searching, I can say that there is no official and trustful (and working) way to do that in the background.
Any ideas, samples, even proofs that it can be done are welcomed! All that matters is that a remote device must have access to that image.
if you want the sending to happen in background you could use android beam, but you would have to get both devices cloth together.
And as i am not sure about what u mean by background i can't be sure that thats what you want. :)
First of all you need to create a "Service" in App which will run in background and do all tasks given below. A central PHP Server required for this task. Other device can download that file by the same HTTP request method.
Convert image to base64 string--
How to convert a image into Base64 string?
you can convert byte array to suitable types- string or delimiter(, or .) separated string
Then create a HTTP request--
Make an HTTP request with android
for HTTP request create a url like this - https://www.yoursite.com/post/?code="base64 string goes here"
-Receive data in php file on your server by $_GET global array
$code = $_GET['code']
In php file convert base64 code to original image.
How to decode a base64 string (gif) into image in PHP / HTML
get image from base64 string
Maybe I explained badly my needs. An important thing I missed is that the same person has access to both device. I solved it by uploading the image to google drive.

Can I create a TriggerIO File instance from Base64 data to pass to forge.request.ajax?

Good day, SO.
Using Trigger.IO's javascript SDK, is it possible to create a Forge File object from Base64 data suitable for passing to Forge's forge.request.ajax method?
I am attempting to upload an image to a server that requires submission in the form of an oldschool multipart/form-data request (can't be changed, unfortunately) from my TriggerIO mobile app. The image comes from canvas.toDataURL() in Base64 format.
Android 2.2 lacks both FormData, BlobBuilder and typed arrays -- making this exercise difficult via XMLHttpRequest (though I have it working well on all other modern platforms). I'm wondering if I might be able to get some joy using Trigger IO's Forge's forge.request.ajax?
Per #James Brady's comment, this cannot be done as of the current version (v1.4).
" The File object has to come from the native side originally "

How to upload image from Android device to Rails server?

I am working on a Android project and want to upload Bitmap images to my rails server. But I have no idea how to write the Rails models or controllers.
I find someone using MultipartEntity post to upload images and paperclip to recieve images on RoR server. I want to know how to connect the post and server (what url?) and how to write the model or controller.
I use a stupid method. I convert the Bitmap image to byte array and use Base64 method to convert it to a string. Post the string to server. When I want to get image, download the string and convert it to Bitmap.

Categories

Resources