J0
12/29/2021, 3:05 PMKebson
12/29/2021, 3:06 PMpython
class KhassidaPost(models.Model):
def upload_image_to_supabase(instance, filename):
filename_base, filename_ext = os.path.splitext(filename)
#Rename this in bucket name
path_name = 'cover/%s-%s' % (
now().strftime("%Y%m%d%H%M%S"),filename)
to_upload = os.path.dirname(os.path.abspath("__file__")) + filename
print(client.storage().StorageFileAPI('qacidas-pdf').upload(path=path_name, file=str(instance.file.path)))
public_upload_path = storage_file.get_public_url(path=path_name)
return public_upload_path
def image_to_supabase():
pass
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=120, null=True, blank=True)
category = models.CharField(max_length=120, null=True, blank=True, default="All")
file = models.FileField(upload_to=upload_image_to_supabase,blank=False,null=False)
coverImage = models.ImageField(upload_to=upload_image_to_supabase, null=True, blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
I tried to link it with my bucket, but it doesn't work.J0
12/29/2021, 3:22 PMsupabase-py
repository
Can I check if qacidas-pdf
is the name of your bucket? StorageFileAPI( )
should take in a bucket so just wanted to be sure. Also, do you happen to have the error message that's returned?
Lmk!Kebson
12/29/2021, 3:46 PMFileNotFoundError: [Errno 2] No such file or directory:
It means the file I try to upload whereas the file exists in the diskKebson
12/29/2021, 5:40 PMclient.storage().StorageFileAPI('qacidas-pdf').upload(path=path_name, file=str(instance.file.path))
called somewhere, I can upload the file. But what I want is, the public path of the uploaded file to be stored in the media field.J0
12/30/2021, 8:56 AMKebson
12/30/2021, 8:57 AMKebson
12/30/2021, 8:58 AMpython
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=120, null=True, blank=True)
category = models.CharField(max_length=120, null=True, blank=True, default="All")
file = models.FileField(upload_to=upload_image_to,blank=False,null=False)
coverImage = models.ImageField( null=True, blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
The file fieldJ0
12/30/2021, 8:59 AMmedia
directory? Via the FileField(upload_to=<storage>)
option?Kebson
12/30/2021, 8:59 AMKebson
12/30/2021, 9:00 AMKebson
12/30/2021, 9:00 AMKebson
12/30/2021, 9:00 AMpython
file = models.FileField(upload_to=upload_image_to,blank=False,null=False)
Kebson
12/30/2021, 9:01 AMJ0
12/30/2021, 9:03 AMKebson
12/30/2021, 9:04 AMJ0
12/30/2021, 9:07 AMKebson
12/30/2021, 9:09 AMjson
{
"url": "http://127.0.0.1:8000/api/postings/56/",
"id": 56,
"user": 2,
"title": "MyTitle",
"category": "All",
"file": "http://127.0.0.1:8000/media/https%3A/custom_url.supabase.co/storage/v1/object/public/qacidas-pdf/cover/20211_zoz3nqC.pdf",
"coverImage": "http://127.0.0.1:8000/media/https%3A/custom_url.supabase.co/storage/v1/object/public/qacidas-pdf/cover/20211_pIpEsbm.png",
"timestamp": "2021-11-09T11:46:20.390642Z"
}
This line, has two url. the local and the supabase url. I'll come back in by the week-end
"http://127.0.0.1:8000/media/https%3A/custom_url.supabase.co/storage/v1/object/public/qacidas-pdf/cover/20211_pIpEsbm.png"
Kebson
12/30/2021, 9:12 AMJ0
12/30/2021, 3:03 PMAnoushk
12/31/2021, 8:43 AMJ0
12/31/2021, 9:00 AMJ0
12/31/2021, 9:01 AMAnoushk
12/31/2021, 9:12 AMJ0
12/31/2021, 10:22 AMJ0
12/31/2021, 10:22 AMdataclasses
module as well so you shouldn't get from typing... dataclass
typing errorsJ0
12/31/2021, 10:24 AMsupabase-0.1.0-py3-none-any.whl
whl file
2. Upload into your repl
3. Run pip3 uninstall supabase
and then pip3 install supabase-0.1.0-py3-none-any.whl
Lmk if you still face any issues!Anoushk
12/31/2021, 10:46 AMAnoushk
12/31/2021, 10:51 AMERROR: Could not install packages due to an OSError: [Errno 22] Invalid argument
Anoushk
12/31/2021, 11:22 AM