0

I have a REST service that retruns byte[] I like to create an image (Ext.Img) which content is the service result

Service

@RequestMapping(value = "/retrieve_thumbnail", method = RequestMethod.GET)
public byte[] retrieveBDocumentThumbnail(@RequestParam String modelName,@RequestParam String modelVersion) throws BdocWebAccessException {
    return service.retrieveBDocumentThumbnail(modelName, modelVersion);
}

Image

 Ext.create("Ext.Img", {
     src:'tablet/bDocument/retrieve_thumbnail?modelName=MODELE_INT_003_TYPES_DONNEES&modelVersion'
})

The service is invocked but I have this message in the javascript Console:

Resource interpreted as Image but transferred with MIME type text/plain: "http://localhost:8080/bdoci-tablet/tablet/bDocument/retrieve_thumbnail?modelName=MODELE_INT_003_TYPES_DONNEES&modelVersion".

I think that the problem is related to the format, How can I fix this?

1

1 Answer 1

2

The MIME type is an HTTP header that indicates what kind of file it is. In this case, it is sending text/plain. It should be indicating this is an image. I don't think your problem is on the client side, but the client is responding to an invalid response on the server side.

 @RequestMapping(value = "/retrieve_thumbnail", method = RequestMethod.GET, 
        produces = MediaType.IMAGE_PNG_VALUE)
Sign up to request clarification or add additional context in comments.

6 Comments

I tried It but, I had the same message: Resource interpreted as Image but transferred with MIME type text/plain
The problem is your mime type. Can you check the network panel on the javascript console? You should see the request. Under the headers section, you should see the mime type. If it is still text/plain, then that is still your problem.
Yes the type still: text/plain,
I have some code that does exactly what you are trying to do. Changing the request mapping with the produces flag worked for me. If this is not working you, then you might have something wrong.
If i put @RestController in the Spring controller, I will have this error in the console " Resource interpreted as Image but transferred with MIME type text/plain" And if I put @Controller , I will have the exception "java.lang.IllegalArgumentException: Unknown return value type [[B]" –"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.