retrofit2 upload image to server












0















I can't upload image to server it send multiple request to server and server is damp



this is my code



 @Multipart
@POST("userImage")
Call<ResponseBody> sendUserFeedback(@Header("SessionID") String authorization, @Part MultipartBody.Part file, @Part("uploadfile") RequestBody name);
}

selectedImageURI = data.getData();

File file = new File(selectedImageURI.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
fileToUpload = MultipartBody.Part.createFormData("uploadfile", file.getName(), requestBody);
filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());

private void executeSendFeedbackFormSendUserImage(String sessionID, MultipartBody.Part fileToUpload, RequestBody description){

UploadImage userClient = retrofit1.create(UploadImage.class);

Call<ResponseBody> call = userClient.sendUserFeedback(sessionID, fileToUpload, description);

call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(AdminEditActivity.this,"success",Toast.LENGTH_SHORT).show();

if (response.body() != null){

response.code();
}

}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(AdminEditActivity.this,"error:",Toast.LENGTH_SHORT).show();
}
});

}


How to fix it???










share|improve this question

























  • Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

    – Shashanth
    Nov 21 '18 at 3:42











  • I get this messaage onFailure method

    – user1899045
    Nov 21 '18 at 8:06











  • What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

    – Shashanth
    Nov 21 '18 at 8:17











  • Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

    – user1899045
    Nov 21 '18 at 8:25











  • this error show when i add HttpLoggingInterceptor

    – user1899045
    Nov 21 '18 at 8:26
















0















I can't upload image to server it send multiple request to server and server is damp



this is my code



 @Multipart
@POST("userImage")
Call<ResponseBody> sendUserFeedback(@Header("SessionID") String authorization, @Part MultipartBody.Part file, @Part("uploadfile") RequestBody name);
}

selectedImageURI = data.getData();

File file = new File(selectedImageURI.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
fileToUpload = MultipartBody.Part.createFormData("uploadfile", file.getName(), requestBody);
filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());

private void executeSendFeedbackFormSendUserImage(String sessionID, MultipartBody.Part fileToUpload, RequestBody description){

UploadImage userClient = retrofit1.create(UploadImage.class);

Call<ResponseBody> call = userClient.sendUserFeedback(sessionID, fileToUpload, description);

call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(AdminEditActivity.this,"success",Toast.LENGTH_SHORT).show();

if (response.body() != null){

response.code();
}

}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(AdminEditActivity.this,"error:",Toast.LENGTH_SHORT).show();
}
});

}


How to fix it???










share|improve this question

























  • Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

    – Shashanth
    Nov 21 '18 at 3:42











  • I get this messaage onFailure method

    – user1899045
    Nov 21 '18 at 8:06











  • What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

    – Shashanth
    Nov 21 '18 at 8:17











  • Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

    – user1899045
    Nov 21 '18 at 8:25











  • this error show when i add HttpLoggingInterceptor

    – user1899045
    Nov 21 '18 at 8:26














0












0








0








I can't upload image to server it send multiple request to server and server is damp



this is my code



 @Multipart
@POST("userImage")
Call<ResponseBody> sendUserFeedback(@Header("SessionID") String authorization, @Part MultipartBody.Part file, @Part("uploadfile") RequestBody name);
}

selectedImageURI = data.getData();

File file = new File(selectedImageURI.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
fileToUpload = MultipartBody.Part.createFormData("uploadfile", file.getName(), requestBody);
filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());

private void executeSendFeedbackFormSendUserImage(String sessionID, MultipartBody.Part fileToUpload, RequestBody description){

UploadImage userClient = retrofit1.create(UploadImage.class);

Call<ResponseBody> call = userClient.sendUserFeedback(sessionID, fileToUpload, description);

call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(AdminEditActivity.this,"success",Toast.LENGTH_SHORT).show();

if (response.body() != null){

response.code();
}

}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(AdminEditActivity.this,"error:",Toast.LENGTH_SHORT).show();
}
});

}


How to fix it???










share|improve this question
















I can't upload image to server it send multiple request to server and server is damp



this is my code



 @Multipart
@POST("userImage")
Call<ResponseBody> sendUserFeedback(@Header("SessionID") String authorization, @Part MultipartBody.Part file, @Part("uploadfile") RequestBody name);
}

selectedImageURI = data.getData();

File file = new File(selectedImageURI.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
fileToUpload = MultipartBody.Part.createFormData("uploadfile", file.getName(), requestBody);
filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());

private void executeSendFeedbackFormSendUserImage(String sessionID, MultipartBody.Part fileToUpload, RequestBody description){

UploadImage userClient = retrofit1.create(UploadImage.class);

Call<ResponseBody> call = userClient.sendUserFeedback(sessionID, fileToUpload, description);

call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(AdminEditActivity.this,"success",Toast.LENGTH_SHORT).show();

if (response.body() != null){

response.code();
}

}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(AdminEditActivity.this,"error:",Toast.LENGTH_SHORT).show();
}
});

}


How to fix it???







android retrofit2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 16:41









Fantômas

32.5k156388




32.5k156388










asked Nov 20 '18 at 14:33









user1899045user1899045

11




11













  • Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

    – Shashanth
    Nov 21 '18 at 3:42











  • I get this messaage onFailure method

    – user1899045
    Nov 21 '18 at 8:06











  • What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

    – Shashanth
    Nov 21 '18 at 8:17











  • Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

    – user1899045
    Nov 21 '18 at 8:25











  • this error show when i add HttpLoggingInterceptor

    – user1899045
    Nov 21 '18 at 8:26



















  • Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

    – Shashanth
    Nov 21 '18 at 3:42











  • I get this messaage onFailure method

    – user1899045
    Nov 21 '18 at 8:06











  • What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

    – Shashanth
    Nov 21 '18 at 8:17











  • Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

    – user1899045
    Nov 21 '18 at 8:25











  • this error show when i add HttpLoggingInterceptor

    – user1899045
    Nov 21 '18 at 8:26

















Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

– Shashanth
Nov 21 '18 at 3:42





Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And inside onFailure() method do not use Toast, use Log.e("TAG", "Error ", t); instead to log error message. After getting error logs, edit the question and post it along with the details I've asked in the beginning of my comment.

– Shashanth
Nov 21 '18 at 3:42













I get this messaage onFailure method

– user1899045
Nov 21 '18 at 8:06





I get this messaage onFailure method

– user1899045
Nov 21 '18 at 8:06













What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

– Shashanth
Nov 21 '18 at 8:17





What's the ERROR MESSAGE? Please edit the question and post relevant information here. Did you read my previous comment clearly? Log error message using Log.e("TAG", "Error ", t); in onFailure() method.

– Shashanth
Nov 21 '18 at 8:17













Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

– user1899045
Nov 21 '18 at 8:25





Error java.io.FileNotFoundException: /document/image:599 (No such file or directory) at java.io.FileInputStream.open0(Native Method) Tis is my error message

– user1899045
Nov 21 '18 at 8:25













this error show when i add HttpLoggingInterceptor

– user1899045
Nov 21 '18 at 8:26





this error show when i add HttpLoggingInterceptor

– user1899045
Nov 21 '18 at 8:26












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395298%2fretrofit2-upload-image-to-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395298%2fretrofit2-upload-image-to-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter