-
Notifications
You must be signed in to change notification settings - Fork 602
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
uploading buffer or string #2334
Comments
Solved:
|
Yes, also |
Thanks for this! I find the support for google cloud platform to be somewhat weaker for node (compared to python) so its great to find someone who's also facing (and solving) similar issues! |
@stephenplusplus how to add metadata & content type before file.save() ? so I able to view or access the image in public ... |
getting issue 'Bucket is requester pays bucket but no user project provided' to save images in GCS. |
Pulled my hair on this while writing a firebase integration test. I'll leave an example for writing a .json from memory here (using admin sdk): const bucket = admin.storage().bucket(testEnv.storageBucket);
const file = bucket.file(mockObject.name);
const contents = JSON.stringify(mockObject, null, 2);
file.save(contents, function(err) {
if (!err) {
// file written
}
}); |
Any way to get saved file back in the callback ? I am using file.save() which works fine but the return response is just []. |
According to the documentation it will return a Promise so you can use: file.save(contents).then(function() {
file.get().then(function (data) {
// use data
}
}); |
Just you can call uploadFile() method passing base64 encode string & get uploaded url videos file
|
Hey there. For me all those methods are not working sadly. Im trying to upload a base64 file via the same method as @manzooralam provided (except the signed url stuff). In the firebase console ui I'm also seeing that there was an upload, but I cant access the file: Any hints for that? |
Greetings! The best way to get help here is to open a new issue in this repo: Best of luck! |
@bayerlse solution for your problem: change the following line
to
This above will create an access token to your file but be sure you wanted it as file then could be accessed by anyone using that access token. |
Hello. Help me Please! Sending base64 to backEnd: const reader = new FileReader()
reader.readAsDataURL(image)
reader.onload = (res) => {
BackEnd('arquivos/setFile', {
image: {
name: image.name,
type: image.type,
size: image.size
},
base64: res.target.result,
})
} Sending base64 to Firebase: const bucket = admin.storage().bucket()
const imageBuffer = Buffer.from(base64, 'base64')
const imageByteArray = new Uint8Array(imageBuffer)
const file = bucket.file(`arquivos/${hash}.png`)
file.save(imageByteArray, {
metadata: {
metadata: {
firebaseStorageDownloadTokens: hash
}
}
}).then(() => {
console.log('Arquivo salvo com sucesso')
return res.status(200).json({})
}) |
Make sure to remove the URI prefix from the base64:
The image will remain broken in Firebase Storage but works when fetching it in your app via path. |
Hi All,
I can only find examples to upload a local file to cloud storage. But I would like to upload a file as a base64 string or as a buffer to google cloud storage.
Is this possible with the google-cloud/storage package?
Regards, Peter
The text was updated successfully, but these errors were encountered: