This is my upload image method
from storages.backends.gcloud import GoogleCloudStorage
storage = GoogleCloudStorage()
def upload_image(file, dir_name, filename):
try:
target_path = '/static/images/' + dir_name + '/' + filename
path = storage.save(target_path, file)
return storage.url(path)
except Exception as e:
print(e)
This is my settings in the django settings.py
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_BUCKET_NAME = 'bucket name'
GS_PROJECT_ID = "project id"
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
os.path.join(BASE_DIR,'google_cloud_credientials.json')
)
I have used this tutorial for reference https://medium.com/@mohammedabuiriban/how-to-use-google-cloud-storage-with-django-application-ff698f5a740f
This is returning me the signed URL for the file which I have uploaded and expired after some time, but I want to have a public URL that will be available for any time.
I want to have a public URL that will be available for any time.
Your only option for a URL that does not expire is to make the object public and use a Google Cloud Storage endpoint in this format:
https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME
Refer to this document:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.