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 –
Hapi, Error 415 : Unsupported Media Type error –

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

How to create android shape background programmatically? –

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

How To Track An iPhone Without Them Knowing

Many iPhone tracking applications can be used to spy on your device,…

Error inflating class androidx.constraintlayout.widget.ConstraintLayout –

Development issue/problem: After switching to Androidx packages via the Android Studio Refactor…

android studio “Use gradle wrapper” grayed out –

Development issue/problem: I’m trying to import an Eclipse project into Android Studio.…