How to create an empty folder on Google Storage with Google API? (Assume that /
is path separator.)
相关问题
- Cannot upload large file to Google Cloud Storage
- Invalidate Google Cloud CDN cache from the backend
- Getting 'Missing required field: member' w
- Script fails on SpreadsheetApp.openById - Requires
- File upload via REST v3 appears as “Untitled”
相关文章
- How to embed Google Speech to Text API in Python p
- Does google-hosted jquery helps google to track vi
- Is there a google API to read cached content? [clo
- Creating GoogleApiClient for multiple activities
- Google Calendar - Permission to Access
- Google OAuth 2: response_type error on token reque
- Google OAuth 2 redirect_uri_mismatch - OmniAuth Ra
- how to implement Google Login API in VueJS?
Node.js
+@google-cloud/storage@^2.5.0
:Only you need do is to assign a destination like:
<folder>/<file Name>
pattern.For below example, I am using
uuid
as my folder name to simulate each user has a folder to store their own files.The result is:
Here is the API docs for
@google-cloud/storage
: https://googleapis.dev/nodejs/storage/latest/Bucket.html#uploadGo
+cloud.google.com/go/storage
Output of stdout:
Check the file in google cloud platform console:
@SheRey - looking at folders created via the GCS web interface, the Content-Type is set to
application/x-www-form-urlencoded;charset=UTF-8
but it doesn't really matter. Here's what worked for me in python:Google Cloud Storage does not have folders or subdirectories. However, there is some support for emulating them. gsutil's How Subdirectories Work is a good read for some background.
Google Cloud Storage objects are a flat namespace, but many tools, including gsutil and the Google Cloud Storage UI, create an illusion of a hierarchical file tree.
There are two widely used conventions for creating the illusion of an empty subdirectory:
(recommended) Create an object that ends in a trailing slash. For example, to create a subdirectory called
foo
at the root of a bucket, you would create an empty object (size 0) calledfoo/
.(legacy) Create an object with
_$folder$
appended to the name. For example, to create a subdirectory calledfoo
at the root of a bucket, you would create an empty object (size 0) calledfoo_$folder$
.Note that most tools and utilities are using method 1 now. Method 2 is less frequently used.
Thank you for the Question and the chosen Best answer. Here is a code snippet that I wrote: Python Method:
main code that calls the method: