Content Type Application Octet Stream

  1. Content-type Application/octet-stream Image
  2. Content Type Application/octet-stream Not Supported
  3. Content Type 'application/octet-stream' Not Supported Postman
  4. Content Type 'application/octet-stream' Not Supported
  5. Header( Content-type: Application/octet-stream )
  6. Application Octet Stream File
  1. Dec 21, 2016  @Wilt if the client wants to save it, then it doesn't matter what headers are sent (you can 'save' or 'save link as' on anything in your browser), as the headers are information, not rules so attachment could be considered 'best not to display this yourself' while inline as 'best to display this yourself if you can'. Either way, most browsers will use the filename value as the suggested name.
  2. May 02, 2017  Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sep 17, 2019  What is MIME Application/Octet-stream? The MIME type application/Octet-stream is considered to be one of the popular multipurpose application files. I added this as a step in VSTS to fix everything I uploaded. As mentioned in the script, if you’re using VSTS I strongly suggest you store the blob key in Azure Key Vault.

Active5 years, 8 months ago

I have a REST controller:

As you can see, I'm trying hard to specify the content type returned by the controller.

It is accessed with a REST client:

The http headers are created by a utility:

The web security configuration and code work fine. I make sure of this using a mockMvc based integration test which succeeds.

The only test that fails is the one based on the REST template:

The exception given in the Maven build console output is:

I'm using the Spring Framework 3.2.2.RELEASE version and the Spring Security 3.1.4.RELEASE version on the Java 1.6 version.

At first, I had a bare bone REST template:

I have now added to it, hoping it would help:

But it didn't change anything and the exception remains the same.

My understanding is that, it is not the REST template that needs any specific JSON configuration, but rather, that, for some reason, my controller is spitting out some application/octet-stream content type instead of some application/json content type.

Any clue?

Some additional information..

The admin rest client bean in the web test configuration:

The base test class:

The web init class:

The web configuration:

The application configuration is empty for now:

Sotirios Delimanolis
221k43 gold badges545 silver badges613 bronze badges
Stephane

Content-type Application/octet-stream Image

Stephane
3,01711 gold badges57 silver badges96 bronze badges

2 Answers

Content Type Application/octet-stream Not Supported

I had my doubts before, but now that you've posted everything, here's what's up. Assuming the RestTemplate object you use in your getGreetingMessage() method is the same as the one declared in the @Bean method, the problem starts here

This call overwrites the default ClientHttpRequestFactory object that the RestTemplate object uses internally with a mock. In your getGreetingMessage() method, this call

doesn't actually go through the network. The RestTemplate uses the mocked ClientHttpRequestFactory to create a fake ClientHttpRequest which produces a fake ClientHttpResponse which doesn't have a Content-Type header. When the RestTemplate looks at the ClientHttpResponse to determine its Content-Type and doesn't find one, it assumes application/octet-stream by default.

So, your controller isn't setting the content type because your controller is never hit. The RestTemplate is using a default content type for your response because it is mocked and doesn't actually contain one.

From your comments: precision auto tune greenville sc

I wonder if I understand what the mock server is testing. I understand it is to be used in acceptance testing scenario. Is it supposed to hit the controller at all ?

The javadoc for MockRestServiceServer states:

Main entry point for client-side REST testing. Used for tests that involve direct or indirect (through client code) use of the RestTemplate. Provides a way to set up fine-grained expectations on the requests that will be performed through the RestTemplate and a way to define the responses to send back removing the need for an actual running server.

In other words, it's as if your application server didn't exist. So you could throw any expectations (and actual return values) you wanted and test whatever happens from the client side. So you aren't testing your server, you are testing your client.

Are you sure you aren't looking for MockMvc, which is

Main entry point for server-side Spring MVC test support.

which you can setup to actually use your @Controller beans in an integration environment. You aren't actually sending HTTP request, but the MockMvc is simulating how they would be sent and how your server would respond.

Sotirios DelimanolisSotirios Delimanolis
221k43 gold badges545 silver badges613 bronze badges

It is bug in MockHttpServletRequest and I will try to describe it.Issue in tracker https://jira.springsource.org/browse/SPR-11308#comment-97327Fixed in version 4.0.1

Bug

When DispatcherServlet looking for method to invoke it using some RequestConditions. One of them is ConsumesRequestCondition. The following is a piece of code:

We are interested in piece request.getContentType(). There request is MockHttpServletRequest. Let's look on method getContentType():

It just return value of this.contentType. It does not return a value from the header! And this.contentType is always NULL. Then contentType in matchMediaType methos will be always MediaType.APPLICATION_OCTET_STREAM.

Solution

I have tried many ways but have found only one that works.

  • Create package org.springframework.test.web.client in your test directory.
  • Create copy of org.springframework.test.web.client.MockMvcClientHttpRequestFactory but rename it. For example rename to FixedMockMvcClientHttpRequestFactory.
  • Find line:

  • Replace it with code:

  • And register your ClientHttpReque

I know that it is not beautiful solution but it works fine.

Avseiytsev DmitriyAvseiytsev Dmitriy

Not the answer you're looking for? Browse other questions tagged javaspringspring-mvcresttemplate or ask your own question.

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign up

Content Type 'application/octet-stream' Not Supported Postman

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments

commented May 2, 2017

My understanding is that the Java SDK sets by default a Content-Type: application/octet-stream header if none is provided by the user when adding an object.
https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/AmazonS3Client.java#L4147

On the other hand, I've noticed that files uploaded via AWS CLI's s3api put-object .. get assigned a Content-Type of binary/octet-stream.
I suppose that this value is assigned by the S3 backend, because I couldn't find any Content-Type header set in the PUT request according to --debug logs.

Uploading a file via the S3 Web console produces a binary/octet-stream MIME type as well.
(For the record, Google Cloud Storage also uses binary/octet-stream.)

I was wondering if you had any comment on this difference between application/octet-stream and binary/octet-stream?

added the Question label May 2, 2017

commented May 2, 2017

Content Type 'application/octet-stream' Not Supported

Hi don't believe the CLI actually sets binary/octet-stream. You can verify this by issuing a command like aws s3 cp MY_BINARY_FILE s3://MY_BUCKET --debug and see that it does not send a Content-Type header.

Per the S3 docs, the default is binary/octet-stream if the header is not set: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

commented May 2, 2017

Oops sorry looks like I didn't read your question close enough! I'm not sure what the exact reason is for the discrepancy but I suspect it's because application/octet-stream is registered with the IANA, and binary/octet-stream does not seem to be. In any case, I don't think it's possible for us to change this now because it would be subtle breaking change for customers.

commented May 3, 2017

Header( Content-type: Application/octet-stream )

Hum, if the default behavior can't be changed (what kind of 'subtle change' do you expect by the way?), what about an option to specify the default MIME type?
Or is the only solution for the API user to explicitly set binary/octet-stream for each PUT operation?

commented May 3, 2017

As far as breaking change, customers may be relying on the fact that the default MIME for objects uploaded using the Java SDK to be application/octet-stream rather than binary/octet-stream.

Do you expect all of your objects to have binary/octet-stream? If so, you can use ClientConfiguration#withHeader. Note that this will override the value set on ObjectMetadata#setContentType so it won't work if the you need to be able to override the default value.

Another option might be a custom RequestHandler

We can also look into adding a default object MIME if that would be easiest for you.

commented May 3, 2017

Thanks for the tips on the various methods available.
I have full control of the code that uses the API so I can explicitly use ObjectMetadata#setContentType for each call, that's not a big deal.
Yet, I am curious what you meant in your last sentence.

commented May 3, 2017
edited

Are you referring to

We can also look into adding a default object MIME if that would be easiest for you.

?

I was imagining just a new option like setDefaultObjectMimeType on S3ClientOptions that works sort of like ClientConfiguration#withHeader but at the S3 level so you can change mimetype per PUT call.

Application Octet Stream File

commented May 3, 2017

Yes, I think such an option would be useful. That would even give some API visibility to the fact that the Java SDK uses a 'non-standard' default MIME type.

added the feature-request label May 3, 2017

commented May 4, 2017

By the way, speaking of 'application/octet-stream' header, I saw in debug traces that (all?) HTTP requests sent to S3 contain such a header, even in case of a GET or HEAD.
I suppose that's not forbidden per se according to the spec, but I find it strange.

removed the Question label May 5, 2017
assigned dagnirMay 15, 2017
Open
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment