-
Notifications
You must be signed in to change notification settings - Fork 88
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
File does not upload correctly with node v16 #267
Comments
Hi @wojtekKrol , thank you for letting us know. |
V2 CDN is used just to GET things, while in order to PUT/POST/DELETE we use Management API which is in V1. |
|
So that is working with you but in combination with Node v16.16.0 you're seeing issues? |
I also updated two main packages responsible for server and upload: I updated |
Understood, so before those updates this was working for you? |
Yeah, excatly. |
@wojtekKrol thank you for all this info. |
I'm afraid I cannot send you all code because it applies to production live applications with confidential data. |
Not a problem, you can either censor the data in the code or send me the portion that is not confidential. |
@VojislavVlasic , Hey. We're working with @wojtekKrol on the same project. So I can describe more accurately what is going on. We're migrating from Node v12 to v16 and after upgrading all needful packages which were listed above we're getting wrong uploaded images in So... Our uploading consists of three layers:
{
filename: 'whatever.jpeg',
asset_folder_id: null,
} In response we get such object:
const form = new FormData();
for (const key in signedRequest.fields) {
form.append(key, signedRequest.fields[key]);
}
form.append('file', stream); // stream - ReadStream, received from client side, createReadStream()
const submitFormPromise = new Promise((resolve, reject) => {
form.submit(signedRequest.post_url, (err, res) =>
err ? reject(err) : resolve(res)
);
});
await submitFormPromise;
Every step was made as it said in instruction here. Previously on Node.js v12 everything worked great, but unfortunately now it's not. Here is an example of GraphQL resolver used with import { FileUpload, GraphQLUpload } from 'graphql-upload';
// other imports
@Mutation(() => AnyReponse)
async uploadPicture(
@Arg('file', () => GraphQLUpload) file: FileUpload
): Promise<AnyResponse> {
const whatever = await this.anyService.processPictureUpload(file);
return { whatever };
} Also, our initialised client is nothing special than just custom wrapper on imported this.client = new StoryblokClient({
oauthToken: personalToken, // token generated from account's settings
accessToken: token, // token generated on Storyblok space
cache: {
clear: 'auto',
type: 'memory',
},
}); If you need more information just let me know. |
Hello guys. I will have a look into this. |
After hours of debugging I figure out that console.log(
stream instanceof ReadStream, // false
createReadStream('anyfile') instanceof ReadStream // true
): I tried to clone data from the And also, I changed a bit POST request configuration. const data = new FormData();
const signedRequest = response?.data;
data.append('acl', 'public-read');
data.append('Cache-Control', 'public; max-age=31536000');
data.append('Content-Type', signedRequest.fields['Content-Type']);
data.append('key', signedRequest.fields.key);
data.append('Expires', signedRequest.fields.Expires);
data.append('policy', signedRequest.fields.policy);
data.append('x-amz-credential', signedRequest.fields['x-amz-credential']);
data.append('x-amz-algorithm', signedRequest.fields['x-amz-algorithm']);
data.append('x-amz-date', signedRequest.fields['x-amz-date']);
data.append('x-amz-signature', signedRequest.fields['x-amz-signature']);
data.append('file', stream);
const len = await new Promise((resolve) => {
data.getLength((_, len) => {
resolve(len);
});
});
const config = {
method: 'POST',
url: 'https://s3.amazonaws.com/a.storyblok.com',
headers: {
...data.getHeaders(),
'Content-Length': `${len}`,
},
data: data,
};
await axios(config); Thanks for your attention. The problem seems to be solved for near future until |
Thank you for letting us know. |
Uploading assets with graphql does not work when using
node v16.16.0
andstoryblok-js-client v4.5.6
This is the code to upload assets:
Im not sure why
responseUrl
path
etc. goes to API v1 when in documentation it goes to API v2This is output of the
reposneUrl
The text was updated successfully, but these errors were encountered: