Can't Open JPG - Error interpreting JPEG image file
I did some sample uploads to OneDrive using graph api. I'm able to upload files (text files) successfully through OkHttp. But, when it comes to images I'm getting this message after opening image
Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)
After uploading images to onedrive. .svg
format images are uploading successfully but .jpg, .png
format images are corrupting when uploading to one drive.
The following is my approach.
Converting the image to Byte array and then converting (writing) that Byte array to uploading file.
String url = "https://graph.microsoft.com/v1.0/drive/root:/" + step.file_name + ":/content";
Request request = new Request.Builder().url(url)
.put(RequestBody.create(MediaType.parse("image/*"), step.file_data))
//step.file_data contains the byte array.
.addHeader("Authorization", String.format("Bearer %s", step.getAccess_token()))
.build();
Response response = okHttpClient.newCall(request).execute();
This approach is working for text files and .svg format images but not for other format images. I went through many references/websites but unable to find a way. What could be the reason?!
Thank you :) in advance
java image-processing https upload
add a comment |
I did some sample uploads to OneDrive using graph api. I'm able to upload files (text files) successfully through OkHttp. But, when it comes to images I'm getting this message after opening image
Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)
After uploading images to onedrive. .svg
format images are uploading successfully but .jpg, .png
format images are corrupting when uploading to one drive.
The following is my approach.
Converting the image to Byte array and then converting (writing) that Byte array to uploading file.
String url = "https://graph.microsoft.com/v1.0/drive/root:/" + step.file_name + ":/content";
Request request = new Request.Builder().url(url)
.put(RequestBody.create(MediaType.parse("image/*"), step.file_data))
//step.file_data contains the byte array.
.addHeader("Authorization", String.format("Bearer %s", step.getAccess_token()))
.build();
Response response = okHttpClient.newCall(request).execute();
This approach is working for text files and .svg format images but not for other format images. I went through many references/websites but unable to find a way. What could be the reason?!
Thank you :) in advance
java image-processing https upload
1
Assvg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know anyjava
, so I'm just commenting, but maybe is an endianness problem?
– Mr Shunz
Jan 17 at 11:33
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
2
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
1
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18
add a comment |
I did some sample uploads to OneDrive using graph api. I'm able to upload files (text files) successfully through OkHttp. But, when it comes to images I'm getting this message after opening image
Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)
After uploading images to onedrive. .svg
format images are uploading successfully but .jpg, .png
format images are corrupting when uploading to one drive.
The following is my approach.
Converting the image to Byte array and then converting (writing) that Byte array to uploading file.
String url = "https://graph.microsoft.com/v1.0/drive/root:/" + step.file_name + ":/content";
Request request = new Request.Builder().url(url)
.put(RequestBody.create(MediaType.parse("image/*"), step.file_data))
//step.file_data contains the byte array.
.addHeader("Authorization", String.format("Bearer %s", step.getAccess_token()))
.build();
Response response = okHttpClient.newCall(request).execute();
This approach is working for text files and .svg format images but not for other format images. I went through many references/websites but unable to find a way. What could be the reason?!
Thank you :) in advance
java image-processing https upload
I did some sample uploads to OneDrive using graph api. I'm able to upload files (text files) successfully through OkHttp. But, when it comes to images I'm getting this message after opening image
Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)
After uploading images to onedrive. .svg
format images are uploading successfully but .jpg, .png
format images are corrupting when uploading to one drive.
The following is my approach.
Converting the image to Byte array and then converting (writing) that Byte array to uploading file.
String url = "https://graph.microsoft.com/v1.0/drive/root:/" + step.file_name + ":/content";
Request request = new Request.Builder().url(url)
.put(RequestBody.create(MediaType.parse("image/*"), step.file_data))
//step.file_data contains the byte array.
.addHeader("Authorization", String.format("Bearer %s", step.getAccess_token()))
.build();
Response response = okHttpClient.newCall(request).execute();
This approach is working for text files and .svg format images but not for other format images. I went through many references/websites but unable to find a way. What could be the reason?!
Thank you :) in advance
java image-processing https upload
java image-processing https upload
edited Jan 17 at 17:41
Zanna
50.7k13135241
50.7k13135241
asked Jan 17 at 10:56
K.venkateshK.venkatesh
186
186
1
Assvg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know anyjava
, so I'm just commenting, but maybe is an endianness problem?
– Mr Shunz
Jan 17 at 11:33
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
2
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
1
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18
add a comment |
1
Assvg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know anyjava
, so I'm just commenting, but maybe is an endianness problem?
– Mr Shunz
Jan 17 at 11:33
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
2
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
1
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18
1
1
As
svg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know any java
, so I'm just commenting, but maybe is an endianness problem?– Mr Shunz
Jan 17 at 11:33
As
svg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know any java
, so I'm just commenting, but maybe is an endianness problem?– Mr Shunz
Jan 17 at 11:33
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
2
2
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
1
1
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18
add a comment |
1 Answer
1
active
oldest
votes
As SVG files are basically XML files (i.e. text files), I suspect your problem is in fact with binary files, most likely an endianness problem.
When the byte array gets assembled and streamed via the network, it isn't written byte-by-byte but aggregated in bigger chunks (probably for speed reasons).
For example, you want to send 4 bytes (ABCD
) from your machine but they get written as BADC
on the remote server.
As why with text files this does not happen... well usually text files composed of simple ASCII chars (unless they're encoded in UTF-8 or such...), so they are handled byte-by-byte instead.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1110522%2fcant-open-jpg-error-interpreting-jpeg-image-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As SVG files are basically XML files (i.e. text files), I suspect your problem is in fact with binary files, most likely an endianness problem.
When the byte array gets assembled and streamed via the network, it isn't written byte-by-byte but aggregated in bigger chunks (probably for speed reasons).
For example, you want to send 4 bytes (ABCD
) from your machine but they get written as BADC
on the remote server.
As why with text files this does not happen... well usually text files composed of simple ASCII chars (unless they're encoded in UTF-8 or such...), so they are handled byte-by-byte instead.
add a comment |
As SVG files are basically XML files (i.e. text files), I suspect your problem is in fact with binary files, most likely an endianness problem.
When the byte array gets assembled and streamed via the network, it isn't written byte-by-byte but aggregated in bigger chunks (probably for speed reasons).
For example, you want to send 4 bytes (ABCD
) from your machine but they get written as BADC
on the remote server.
As why with text files this does not happen... well usually text files composed of simple ASCII chars (unless they're encoded in UTF-8 or such...), so they are handled byte-by-byte instead.
add a comment |
As SVG files are basically XML files (i.e. text files), I suspect your problem is in fact with binary files, most likely an endianness problem.
When the byte array gets assembled and streamed via the network, it isn't written byte-by-byte but aggregated in bigger chunks (probably for speed reasons).
For example, you want to send 4 bytes (ABCD
) from your machine but they get written as BADC
on the remote server.
As why with text files this does not happen... well usually text files composed of simple ASCII chars (unless they're encoded in UTF-8 or such...), so they are handled byte-by-byte instead.
As SVG files are basically XML files (i.e. text files), I suspect your problem is in fact with binary files, most likely an endianness problem.
When the byte array gets assembled and streamed via the network, it isn't written byte-by-byte but aggregated in bigger chunks (probably for speed reasons).
For example, you want to send 4 bytes (ABCD
) from your machine but they get written as BADC
on the remote server.
As why with text files this does not happen... well usually text files composed of simple ASCII chars (unless they're encoded in UTF-8 or such...), so they are handled byte-by-byte instead.
answered Jan 18 at 9:48
Mr ShunzMr Shunz
2,41121922
2,41121922
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1110522%2fcant-open-jpg-error-interpreting-jpeg-image-file%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
1
As
svg
files are basically xml files (i.e.) text, I suspect your problem is in fact with binary files. I don't know anyjava
, so I'm just commenting, but maybe is an endianness problem?– Mr Shunz
Jan 17 at 11:33
Thanks for the comment, I believe you're right. I had just come to the same conclusion but what can be wrong with byte/binary array!
– K.venkatesh
Jan 17 at 12:10
2
It might be that the byte array isn't written byte-by-byte but aggregated in some way (for speed?). I.e. you send 4 bytes ABCD from your machine but they get written as BADC on the remote server. As text files usually composed of simple ASCII chars, they might be handled byte-by-byte instead.
– Mr Shunz
Jan 17 at 12:14
1
@MrShunz you are right mate. The problem is with the byte array itself. It took me whole day to figure out :(
– K.venkatesh
Jan 18 at 5:18