I am trying to Upload an image taken from Camera or Gallery to a php server. To do so I am using the library Fast-Android-Networking
With my code I can see the file is writing in the server however, it is saved with 0 B
, also the onProgress
function is logging out the correct bytes written.
Any help with This? How can I properly pass the file taken from the camera or gallery to the server using this library?
private File mFileTemp;
btn_update.setOnClickListener(new OnClickListener() {
// Start new list activity
public void onClick(View v) {
uploadFileNew(pref.getString("user_id", null));
}
});
public void uploadFileNew(String frm_iduser) {
String uploadUrl = "https://plus.example.com/apps/mobile/registered_users/uploadProfilePicAndroid.php?fileName=" + frm_iduser + ".png";
AndroidNetworking.upload(uploadUrl)
.addMultipartFile("image",mFileTemp)
.addMultipartParameter("key","value")
.setTag("uploadTest")
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
// do anything with progress
Log.d("responce_app",String.valueOf(bytesUploaded));
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
// do anything with response
Log.d("responce_app",String.valueOf(response));
}
@Override
public void onError(ANError error) {
// handle error
Log.d("responce_app",String.valueOf(error));
Log.d("responce_app","errorrrr");
}
});
}
There seems to be nothing wrong with your code. Looks like your server-side code is at fault here.
Post the contents of
uploadProfilePicAndroid.php
so we can find the problem.Also, there is no need to pass the file name in the address:
String uploadUrl = "https://plus.example.com/apps/mobile/registered_users/uploadProfilePicAndroid.php?fileName=" + frm_iduser + ".png"
In the php code you can access the file using the name
"image"
you specified here:Furthermore, whenever you DO need to send additional data in your request, do it using the library and not the address, as you did with
"key"
and"value"
: