Reputation: 1057
Appears images uploaded using node library appear to be broken though they report the right size.
A similar issue was reported regarding using Java/PHP
let fileName: string = `public/static/${data["name"]}`;
let file: Storage.File = this.bucket.file(fileName);
var fileBuffer = Buffer.from(data["source"], 'base64');
return from(file.save(fileBuffer, { contentType: data["contentType"], public: data["isPublic"] }))
.pipe(map(() => {
return { source: `${this.publicURLPrefix}/${fileName}` }
}));
With the above code, image file is successfully upload, code converts base64 uploaded content and writes to file specified. However upon browsing to public URL the image appears corrupted/broken. Manually uploaded image works as expected.
Upvotes: 0
Views: 597
Reputation: 1057
tired solution posted here regarding node storing broken images, and it appears meta information in base64encoded image needs to be removed. Updated working code below
let fileName: string = `${namespace}/${data["name"]}`;
let file: Storage.File = this.bucket.file(fileName);
//add acl, who has access to this file
console.debug("creating/modifying file", fileName);
let base64Source = (data["source"] as string).replace(/^data:image\/(png|gif|jpeg);base64,/,'');
let fileBuffer = new Buffer(base64Source,'base64');
return from(file.save(fileBuffer, { contentType: data["contentType"], public: data["isPublic"] }))
.pipe(map(() => {
return { source: `${this.publicURLPrefix}/${fileName}` }
}));
Upvotes: 2