retrofit2 upload image to server
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???

|
show 2 more comments
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???

Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And insideonFailure()
method do not use Toast, useLog.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 usingLog.e("TAG", "Error ", t);
inonFailure()
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
|
show 2 more comments
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???

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???


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 insideonFailure()
method do not use Toast, useLog.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 usingLog.e("TAG", "Error ", t);
inonFailure()
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
|
show 2 more comments
Your question is not clear. Which server are you using? What's the Android OS version in which you're testing the app? And insideonFailure()
method do not use Toast, useLog.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 usingLog.e("TAG", "Error ", t);
inonFailure()
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
|
show 2 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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, useLog.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);
inonFailure()
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