Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

Issue while uploading Image

Open ApporioInfolabs opened this issue 6 years ago • 12 comments

Sir, Library throws an Exception Illegal State Exception (closed) while uploading the file as multipart. Please check

ApporioInfolabs avatar Jun 18 '19 11:06 ApporioInfolabs

Can you please provide me more detail like request?

amitshekhariitbhu avatar Jul 16 '19 18:07 amitshekhariitbhu

I am having the same issue, here's an what I am doing, hope this helps:

val imageFile = File(uri.path!!)
if (imageFile.exists()) {
     println("imageFile check $imageFile")
} else {
     println("imageFile does not exist")
}

I do get confirmation that file exists and I made myself an Alertview to confirm that the Uri I am using points to the correct image.

Then using the file I send an upload request with your wonderful Library:

AndroidNetworking.upload("https://url.com/api/photo/upload")
                                     .addHeaders("Auth",  managerToken)
                                     .addMultipartParameter("parent_id", parentIdString)
                                     .addMultipartParameter("parent_type", parentTypeString)
                                    .addMultipartFile("file", imageFile)
                                    .addMultipartParameter("comment", imageCommentString)
                                    .setPriority(Priority.HIGH)
                                    .build()

I get the error message:

error: com.androidnetworking.error.ANError: java.lang.IllegalStateException: closed

This was working very well until I updated Android Studio, I'm not sure if it's a coincidence though.

philblais avatar Aug 13 '19 02:08 philblais

have you solved the issue?

I am getting the exact error error: com.androidnetworking.error.ANError: java.lang.IllegalStateException: closed

keskin avatar Jan 24 '20 22:01 keskin

have you solved the issue?

I am getting the exact error error: com.androidnetworking.error.ANError: java.lang.IllegalStateException: closed

Keskin, is the file you are trying to upload a saved photo uri?

philblais avatar Jan 24 '20 22:01 philblais

Yes, it is a photo from the gallery. I am using Rx2AndroidNetworking

Rx2AndroidNetworking.upload(ApiEndPoint.ENDPOINT_UPLOAD_PHOTO)
                .setOkHttpClient(okHttpClient)
                .addMultipartFile("file", file)
                .build()
                .getObjectObservable(ApiResponse.class);

When I check out Stetho, I can see that it generates the request with headers, but I see that the response is empty. I think it can't send to the server. When I check the server logs, I see that this request has not been received.

keskin avatar Jan 25 '20 10:01 keskin

I have disabled stetho in okHttpClient and now it is working. Is there any way to get this done without disabling the logging?

keskin avatar Jan 25 '20 12:01 keskin

I have the same problem

ModoumbeneDIOUF avatar Feb 02 '20 12:02 ModoumbeneDIOUF

I have the same problem

ModoumbeneDIOUF avatar Feb 02 '20 12:02 ModoumbeneDIOUF

I am also facing same problem.

nirmalrevar avatar Jun 11 '20 06:06 nirmalrevar

I am getting this error

com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.io.FileNotFoundException: /document/document:57027: open failed: ENOENT (No such file or directory)

here is my code:

AndroidNetworking.upload(Config.add_assignment) .addMultipartParameter("subject_id", getSubjectId) .addMultipartParameter("subject_name",getSubjectName) .addMultipartFile("assigment", new File(PathHolder)) // .addMultipartFile("assigment", new File(encodedPdf)) .setContentType("Content-type: multipart/form-data; charset=utf-8") .setTag("addAssignment") .setPriority(Priority.MEDIUM) .build()

 .getAsString(new StringRequestListener() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(AddPdf_StudyMaterialActivity.this,"File Uploaded Successfully......!", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(AddPdf_StudyMaterialActivity.this, StudyPortalActivity.class);
                    startActivity(intent);
                    finish();
                }

itinnovertech avatar Jun 15 '21 03:06 itinnovertech

I am also having the same problem. Is there any solution for this?

spapapan avatar Jul 16 '21 19:07 spapapan

I am also having the same problem. Is there any solution for this?

maksure logging feature is not active

inyong1 avatar Aug 05 '21 09:08 inyong1