hgoebl / DavidWebb

Lightweight Java HTTP-Client for calling JSON REST-Services (especially for Android)
https://hgoebl.github.io/DavidWebb/
MIT License
127 stars 41 forks source link

Send a file on request #11

Closed LuisDominguez closed 9 years ago

LuisDominguez commented 9 years ago

Hello i add a video file on request

            Uri uri_video = Uri.parse(temp_usuario.getString("video_url"));
            File file = new File(getPath(uri_video));
            Webb webb = Webb.create();
            Response<String> response = webb
                    .post(getString(R.string.REST_URL) + "acciones_de_app/create_user.json")
                    .body(file)
                    .connectTimeout(10 * 3000)
                    .asString();

            if (response.isSuccess()) {
                String outcome = response.getBody();
                Log.e("a",outcome);

            } else {
                System.out.println(response.getStatusCode());
                System.out.println(response.getResponseMessage());
                System.out.println(response.getErrorBody());
            }

But when i recieved a body on action post

file = request.body.read fp = File.open("/home/master/Escritorio/video_rest/video_mp.mp4", "wb") fp.write(request.body.read) fp.close

my file video_mp.mp4 created size a 0 byte

hgoebl commented 9 years ago

I'd check 2 things:

LuisDominguez commented 9 years ago

Hello thanks for resonder

first point: Yes file exist and really ponting for video file

second point: i puts a request.body.read and not empty have A

im try with image=nil StringIO.open(request.body.read) do |data| data.class.class_eval { attr_accessor :original_filename, :content_type } data.original_filename = "temp#{DateTime.now.to_i}.mp4" data.content_type = "video/mp4" image = data end

fp = File.open("/home/aa/vv/video_rest/video_mp.mp4", "wb") fp.write(image) fp.close

is ruby on rails but i dont know if body http content are correct

LuisDominguez commented 9 years ago

for this second try, 24bytes is size for file result

hgoebl commented 9 years ago

24 bytes implies there is some kind of error. Probably you'll have to debug client-side and/or server-side. I'm afraid I cannot help you from distance... The tests for File-upload of DavidWebb pass. I suppose it's something on the server side.

LuisDominguez commented 9 years ago

thanks, but i used other libreary to send file with params on headers dont on body, on ruby on rails dont get a file on request.body