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

Upload an image using PUT method instead of POST (MultiPartBuilder)

Open adesousabarroso opened this issue 8 years ago • 18 comments

Hi, I need to upload an image using PUT method but ANRequest mMethod property is set to POST in the contructor for MultiPartBuilder parameter;

public ANRequest(MultiPartBuilder builder) { this.mRequestType = RequestType.MULTIPART; this.mMethod = Method.POST; ... }

¿How can I solve this?

Thanks in advance. Antonio

adesousabarroso avatar Jun 10 '18 12:06 adesousabarroso

Hi Amit, if I cannot solve this issue I have to move to another networking library as Retrofit.

Thanks

adesousabarroso avatar Jun 13 '18 09:06 adesousabarroso

I will check it on weekend.

amitshekhariitbhu avatar Jun 13 '18 09:06 amitshekhariitbhu

Hi Amit, did you have time to check my issue on weekend?

Thank you

adesousabarroso avatar Jun 18 '18 08:06 adesousabarroso

Hi Amit, I would like to know if it is possible to solve my issue as soon as possible,... If you have to upload a image file related to an idempotent resource you can not use POST but PUT.

POST /v1/deliveries PUT /v1/deliveries/{id}/labelPhoto

Please, let me know...

adesousabarroso avatar Jun 19 '18 21:06 adesousabarroso

@adesousabarroso can you provide me the url to test and confirm you?

amitshekhariitbhu avatar Jun 20 '18 02:06 amitshekhariitbhu

@amitshekhariitbhu I'm sorry but at this moment I cannot provide you a live endpoint for you to confirm. The backend team has told me that they will implement it soon... I have already finished the v1 of the client...

I don't know if API Tester could help you https://apitester.com/

Thanks a lot

adesousabarroso avatar Jun 20 '18 09:06 adesousabarroso

Hi @amitshekhariitbhu, could you provide me a test version of your lib that uses PUT instead of POST?

Thank you

adesousabarroso avatar Aug 13 '18 16:08 adesousabarroso

Hi @amitshekhariitbhu, I'd need to know if you can help me with this or not, otherwise I'll have to take an alternative action.

Thank you in advance

adesousabarroso avatar Aug 21 '18 16:08 adesousabarroso

Hi @amitshekhariitbhu, thank you anyway.

adesousabarroso avatar Aug 31 '18 10:08 adesousabarroso

@adesousabarroso your suggestion was good. Can we make this soon? help us here to build that quickly. Open for PR from your side also.

amitshekhariitbhu avatar Aug 31 '18 11:08 amitshekhariitbhu

Hi Amit, this week I'll try/test the PUT method to upload a file (idempotent). Then I'll be back to you to tell you if it works and send you the changes I've made.

adesousabarroso avatar Sep 03 '18 17:09 adesousabarroso

Hi Amit, I have resolved an uploada a file using PUT verb (idempotent) but I haven't used multipart as follows:

ANRequest.PutRequestBuilder builder AndroidNetworking.put( URL );

    builder.addHeaders("Cache-Control", "no-cache")
               .addHeaders("Connection", "keep-alive")
               .addFileBody( FILE_TO_UPLOAD )
               .setContentType("image/png")      // IMPORTANT: image/*
               .setTag( TAG )
              .setPriority(Priority.IMMEDIATE);

ANRequest request = builder.build();

        request.getAsOkHttpResponse(new OkHttpResponseListener() {
            @Override
            public void onResponse(Response response) {
                  // Check response.code()
            }
            @Override
            public void onError(ANError error) {
                  // Error
            }
        });

Ciao

adesousabarroso avatar Sep 11 '18 19:09 adesousabarroso

Hello, this was solved?

I also need to upload an image using PUT multipart. Or how can it be resolved?

adriandleon avatar Sep 14 '18 13:09 adriandleon

need to upload using post method multipart, why addFileBody not have key ?

winnerawan avatar Oct 13 '18 09:10 winnerawan

@amitshekhariitbhu i'm always use put to update user profile avatar.But .addFileBody() does not have key. I dont want to replace your lib to retrofit. thanks

builder.addHeaders("Cache-Control", "no-cache") .addHeaders("Connection", "keep-alive") .addFileBody( FILE_TO_UPLOAD ) .setContentType("image/png") // IMPORTANT: image/* .setTag( TAG ) .setPriority(Priority.IMMEDIATE);

ltthuc1989 avatar Feb 27 '19 02:02 ltthuc1989

@ltthuc1989 let me check

amitshekhariitbhu avatar Feb 27 '19 02:02 amitshekhariitbhu

are you still checking?

rajscet avatar May 15 '19 18:05 rajscet

someone find the solution, please tell

himanshu-mindfulai avatar Jun 18 '21 12:06 himanshu-mindfulai