`upload()`和`save()`在存储方面有什么区别?

huangapple go评论115阅读模式
英文:

What is the difference between upload() and save() for storage?

问题

我正在尝试弄清楚如何使用Google Cloud Functions将图像上传到Firestore,我看到有upload()和save()方法。我还没有弄清楚它们之间的区别以及何时应该使用其中一个或另一个。您可以告诉我每种方法何时适合使用以将图像上传/保存到Firestore使用Google Cloud Functions吗?

示例:

await bucket.upload({destination, contentType})

await bucket.file().save()

英文:

I am trying to figure out how to upload images to firestore using Google Cloud Functions, and I see there are upload() and save() methods. I haven't been able to figure out the difference between them and when you should use one or the other. Can you tell me when each method is appropriate to use to upload/save an image to Firestore using Google Cloud Functions?

Example

await bucket.upload({destination, contentType})

await bucket.file().save()

答案1

得分: 1

如@Doug Stevenson所述:

看起来你可以选择最适合你的用例的那种方式。有时API提供多种方法来做某事以方便使用。

如@epascarello所述:

googleapis.dev/nodejs/storage/latest/File.html#save 与 googleapis.dev/nodejs/storage/latest/Bucket.html#upload,请查看参数差异。

你可以在这个链接中查看参数的不同之处:Save vs Upload

save() 函数用于当你已经将文件数据保存在内存中并想要直接存储到云存储时,而 upload() 方法通常用于当你想要将文件从本地系统或服务器移动到云存储时。同样,最好选择适合你用例的方法。

英文:

As mentioned by @Doug Stevenson:
> Seems to me you could just pick the one that works best for your use case. Sometimes APIs provide more than one way of doing something as a convenience.

<hr>

As mentioned by @epascarello:
>googleapis.dev/nodejs/storage/latest/File.html#save vs googleapis.dev/nodejs/storage/latest/Bucket.html#upload look at the parameters

You may check the parameters difference in this link: Save vs Upload

<hr>

The save() function is used when you already have the file data in memory and want to store it directly in Cloud Storage, whereas the upload() method is often used when you want to move a file from your local system or server to Cloud Storage. Again, it is best to choose that works best for your use case.

huangapple
  • 本文由 发表于 2023年7月6日 21:53:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定