i am using webcomponent vaadin upload to upload files using multipart when i am using
<vaadin-upload id="calibration"
target="https://blobstore-uploadpredix.run.aws-usw02-pr.ice.predix.io/idp/api/v1/upload?gyroname=Eg0123">
<iron-icon slot="drop-label-icon" icon="description"></iron-icon>
<span slot="drop-label">Drop your calibration file</span>
</vaadin-upload>
i am able to hit directly to endpoint i am able to upload and hit the server. but when i am redirecting this api to express for appending some token i am not able to hit the api i kept on getting 500 internal server app.js if (config.postCalibration && config.postCalibration.indexOf('https') === 0) {
app.post('/idp/api/v1/upload', passport.authenticate('main', {
noredirect: true
}),
// if calling a secure microservice, you can use this middleware to add a client token.
proxy.addAccessTokenMiddleware,
proxy.customProxyMiddleware('/idp/api/v1/upload', config.postCalibration, '/data/idp/api/v1/upload')
);
}
@Greg Stroup can you please help i am getting 500 server error while trying to hit multipart file from express server?
Answer by Greg Stroup · Oct 09, 2017 at 08:57 AM
I haven't used the vaadin-upload
component before, but it looks like you are bypassing the Express server, and going directly to the blobstore service from your browser application. Your browser should post to /idp/api/v1/upload
. Then an Express middleware function will add the token for you.
Hi @Greg Stroup i removed the vaadin upload and using iron form to post data to express js, but multipart request is not going through express when i use
app.post('/idp/api/v1/upload', passport.authenticate('main', { noredirect: true }), // if calling a secure microservice, you can use this middleware to add a client token. proxy.addAccessTokenMiddleware, proxy.customProxyMiddleware('/idp/api/v1/upload', config.postCalibration, '/data/idp/api/v1/upload') ); }
can you please let me know what changes has to be made in middleware function in app.js for a proxy of multipart request?
Right now, the proxy.js file only supports application/json
. You'll need to write a little code to use a different content type, like multipart. Here's where the content-type is set right now...
https://github.com/PredixDev/predix-webapp-starter/blob/master/server/routes/proxy.js#L88