How do I use androidHttp to upload multipart video to server - android

According to the android documentations, I should be using AndroidHttp.HttpTransport instead of Apache as Apache may not be supported in the future, etc. etc. Does anyone know how to use AndroidHttp for sending multipart data to server? I need to upload a video to server along with title, username, timestamp, etc. Thanks for any help.
With apache, the following code works well for uploading multipart video: Android upload video to remote server using HTTP multipart form data

Related

What is best solution file upload for python server

I programming python server and android client.
program's logic is client send multiple file to server.
I first try C/C++ socket server but receive error. so I change python. because server on raspberry pi.
I have to implement file upload, audio streaming. so I think this logic.
1. Client send http request to server
2. When server receives the request, server create tcp socket and listen.
3. Client receives success response, connect to server and file upload.
Audio streaming will implement similar way.
Is it ok to implement this way? or is there a better way?
Please give me a hint how to implement it.
Ignore socket as much as you for small deployments. They are little more complicated to handle.
Now asuming you want to upload a image file or some other file to a python you can use Flask Upload
Next move on to audio, if you have to upload audio from client to server, than there is no need to stream or stuff, just pass appropriate MIME type during upload.
ALLOWED_AUDIO_EXTENSIONS = set(['wav', 'ogg', 'mp3', ])
def audio_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_AUDIO_EXTENSIONS
if file and audio_file(file.filename):
filename = secure_filename(file.filename)
#perform some application logic with audio files and then save them in file system or call boto3 to save on s3
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
Code is modified from flask examples.

Google Cloud Storage uploads with OkHttp - streaming vs multipart

I'm using OkHttp to upload files to Google Cloud Storage. Right now, I'm doing a single PUT request with a custom request body and stream the data. The request is something like this:
final Request request = new Request.Builder()
.url(uploadUrl)
.put(requestBody)
.addHeader("Content-Length", length)
.addHeader("Content-Range", range)
.build();
My requestBody handles reading of the file and writing to the BufferedSink, similar to the recipe for Post Streaming available here (https://github.com/square/okhttp/wiki/Recipes):
Will it be faster to move to uploading Multiple Chunks (as described here: https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#upload-resumable - I think it should be achievable with OkHttp MultipartBody.Builder), or should I stick with streaming?

Android upload image via HTTP PUT

I'm trying to upload a jpeg image to my web server via an HTTP PUT method.
With Fiddler, I'm able to compose an HTTP PUT request, upload the image and execute the request successfully.
However, on Android, I can't get it to work. I've read many solutions about using MultipartEntity. When I try that, the image received on the server is corrupted. I compared the content of the original image with the one received by the server and I see that some HTTP headers are added at the beginning of the file and that the multipart boundary is added at the end, therefore corrupting it.
I've set up Fiddler on the web server as a reverse proxy to capture the incoming HTTP traffic:
here's the result
On the top, the HTTP PUT request sent with Fiddler that works.
At the bottom, the one sent by my Android application that sends a corrupted image.
How can I send an HTTP PUT request on Android that will produce a similar request than the one sent with Fiddler?

get push stream in response send by server push with OkHttp

I am trying to test the push response from a server which support HTTP2 Server with an android app (Os=Android KitKat) . The server push another ressources(pictures) after a http request for index.html.
I don't know how to access to push stream (picture). I have done capture on server and it send the push stream. But the client (Okhttp 2.1.0) always send a frame RST_STREAM and just return the index page content .
I just start use okhttp and would like to know how to acces push stream from Okhttpclient response ? I have read that that it exist API for handle push stream from HTTP2. is it available in Okhttp 2.1.0 or Okhttp 2.2.0?
Thanks.
OkHttp doesn't implement pushed streams yet. When we do, it'll likely be to push into the cache only.

Struts2 - Upload photo from Android to Server via Restful

I would like to upload photo from Android client to Web Server via Restful like this:
URL:
http://domain.com/users/{user_id}/list
Method: POST
Content-type Image/JPEG
Server receive photo. But I don't know how to receive and save to folder.

Categories

Resources