Application Programming Interface (API) Problem:

I’m trying to send a json feedData object to the server. This object contains a file object.

feedData = {
‘title’ : ‘some title’ ,
‘type’ : 1,
‘feedBody’ : {
‘image’ : Object of the file {lastModified: xxxx, name: ‘image.jpg’, type: ‘image/jpg’, .
}
}

return shipment (`/api/feeds/${feedId}/creation`, {
method : ‘POST’,
body : JSON.stringify(feedData),
headers : {
‘Authorization’ : getTokenHeader(token),
},
})

I did,

Method: POST, path
: /api/feeds/{feed}/create, configuration
: {
payload: [output
: stream,
parse: true,
solved : [application/json, multipart/form-data, image/jpeg, application/pdf, application/x-wwww-form-urlencoded],
maxBytes: 1024 * 1024 * 100,
timeout: false
},
handler : (req, res) => {
const params = { token : req.auth.token, …req.params } ;
const payload = req.payload ;
console.log(‘HAPI’, payload) ;
},
auth : {
strategy : ‘jwt-strict’,
mode : ‘required’
}
}

I understand the mistake

http://localhost:3000/api/feeds/feed/create 415 (media type not supported)

What am I doing wrong?

How do you solve the API problem?

Solution 1:

I searched and I didn’t find the right answer.
Looks like I’m impotent. But fortunately, the visua code helped debug the code, and I found this line in the [email protected]/subtext/lib file.

If (contentType.mime === ‘multipart/form-data’) {
if (options.multipart ==== false) {// Default
throw Boom.unsupportedMediaType() ;
}.

return waits internals.multipart (req, options, source, contentType);
}

Then I corrected the multiple = truth in the way opiates:

{
payload: {
maxBytes: 1024 * 1024 * 100,
// timeout: false, // important
parse: true, output
: data,
allowed: multi-part / form data’,
multi-part: true
}
}.

and it worked. Thanks for debugging the Visua code. I’ve been responding to someone who may be receiving this error. I know how to do this.

I’m using version 19.0.3 of Hapi.

Solution 2:

Works for me.

server.route({
handler : (request: any) =>
dit.uploadProfileImage(request, profileService), method
: POST,
options: {
auth : false,
payload: {
maxBytes: 1024 * 1024 * 5,
multipart: {
output: file
},
parse: true
},
plugins: {
hapi-swagger: {
payloadType: form
}
},
tags : api, this.controllerName],
confirm: {
payload: Joi.object({ image
: Joi.any().meta({ swaggerType: file })
})
}
}, path
: `/api/${this.controllerName}/upload`
})

And my factor request below –
Fill in the image description here

Solution 3:

This is what worked,

On the forehead 🙂

const request = new XMLHttpRequest() ;
const formData = _getFileFormData(file) ;

request.open(‘POST’, url);
request.setRequestHeader(‘authorization’, getTokenHeader(token));
request.send(formData) ;

And in the back: –

Method: POST, path
: /api/feeds/{feed}/create, configuration
: {
handler: function (req, res) {
const pre = preFilter(req.pre) ;
const token = req.auth.token ;
const params = { …req.params, …pre.params, token : token } ;
const payload = req.payload ;
return UploadAction.with(req, res).actionUploadToFeed(params, payload) ;
},
payload : { output
: stream,
parse : true,
allow : ‘multipart/form-data’,
maxBytes : 1024 * 1024 * 100,
timeout : false,
},
validate : {
params : {
…FeedsController.numerValidator(FeedsController.PARAM_CLIENT),
…FeedsController.numerValidator(FeedsController.PARAM_FEED),
},
},
pre:
…TransformParam.toLowerCase(FeedsController.PARAM_CLIENT),
…TransformParam.toLowerCase(FeedsController.PARAM_FEED),
],
auth : {
strategy : ‘ywt-strict’,
mode : ‘required’,
},
}.

Good luck!

unsupported media type postman,415 unsupported media type web api,unsupported media type 415 null,415_client_error,415 unsupported media type postman c#,415 unsupported media type stack overflow,{ "statuscode": 415, "error": "unsupported media type", "message": "unsupported media type" },hapi response json,hapi redirect,415 unsupported media type node js,hapi cors,hapi response toolkit,415 unsupported media type angular 8,hapi stream response

You May Also Like

Microsoft’s Surface ‘Centaurus’ foldable device might be coming soon

We’ve seen a few reports about Microsoft working on a foldable tablet,…

BestHDMovies | One stop for all HD Quality movies (besthdmovies.me)

Hi! This is a place where you can find all the latest…

Types Of CBD Products To Buy Wholesale

Buying CBD products in bulk: CBD or cannabidiol has been on the…

How to create android shape background programmatically? –

Development issue/problem: How do I create this form programmatically? I have tried…