php - Can't send image to server with Retrofit -


i'm using retrofit library upload file php server unknow error occurs.

here android code :

retrofit service :

@multipart @post("/upload_image.php") public void uploadimage(@part("file") typedfile file, @query("id_client") long id_client, @query("id_obj") long id_obj, callback<boolean> callback); 

upload code :

public void uploadimage(string imagepath, long, clientid, obj obj, callback<boolean> callback) {     typedfile typedfile = new typedfile("application/octet-stream", new file(imagepath));     mservice.uploadimage(typedfile, clientid, obj.getid(), callback); } 

php code :

if(move_uploaded_file($_files["file"]["tmp_name"],  $destination)){    echo ("stored     in".$_server[document_root]."/uploader/uploadedfiles/".$_files["file"]["name"]); } else { $html_body = '<h1>file upload error!</h1>'; switch ($_files[0]['error']) { case 1:    $html_body .= 'the file bigger php installation allows';    break; case 2:    $html_body .= 'the file bigger form allows';    break; case 3:   $html_body .= 'only part of file uploaded';   break; case 4:    $html_body .= 'no file uploaded';    break; default:    $html_body .= 'unknown errror'; }  echo ($html_body); } 

on image upload, server returns : "unknown errror".

that because switch defaults unknown error, , upload_err_ok has value of zero

therefore should check if $_files['image']['error'] has value of 0 , if so, skip error handling

actually looks move_uploaded_file fails, hard tell not knowing $destination variable points to

but should check if $destination valid file write , process has permissions write there

also coding practice shouldn't use magic values such 1, 2, 3.. use constants instead! upload_err_ok, upload_err_no_file..

..

also looks you've tried form , works

you should check if typedfile in device points existing file

i using retrofit in same way , working perfectly

if fails, try monitoring traffic using http traffic monitoring proxy such charles

and see if file gets sent

but typedfile doesn't point valid file


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -