Closed camenduru closed 1 month ago
here when i upload my file using axios i get the response but when i open the fileurl the file say Your file is currently being uploaded...
This page will automatically refresh once it's done.
This function is working.
def upload_file_to_uploadthing(file_path):
file_name = os.path.basename(file_path)
_, file_extension = os.path.splitext(file_name)
random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
file_name = md5_hash+file_extension
file_size = os.path.getsize(file_path)
file_type, _ = mimetypes.guess_type(file_path)
with open(file_path, "rb") as file:
file_content = file.read()
file_info = {"name": file_name, "size": file_size, "type": file_type}
uploadthing_api_key = os.getenv('uploadthing_api_key')
headers = {"x-uploadthing-api-key": uploadthing_api_key}
data = {"contentDisposition": "inline", "acl": "public-read", "files": [file_info]}
presigned_response = requests.post("https://api.uploadthing.com/v6/uploadFiles", headers=headers, json=data)
presigned_response.raise_for_status()
presigned = presigned_response.json()["data"][0]
upload_url = presigned["url"]
fields = presigned["fields"]
files = {"file": file_content}
upload_response = requests.post(upload_url, data=fields, files=files)
upload_response.raise_for_status()
return presigned_response, upload_response, file_name
hello could you help me
const data = { files: files.map((file) => ({ name: file.file.name, size: file.file.size, type: file.file.type, })), acl: 'public-read', contentDisposition: 'attachment', }; const options = { method: 'POST', url: 'https://api.uploadthing.com/v6/uploadFiles', headers: { 'Content-Type': 'application/json', 'X-Uploadthing-Api-Key': process.env.NEXT_PUBLIC_UPLOADTHING_SECRET }, data: data };
i am using axios
and the fileurl i get wont open it say it is uploading
hello which url is used to access the files
I understand that this issue may be closed if it should be filed in another category
My issue
Hi I am new 👋 It is stuck. Do I need to call https://api.uploadthing.com/v6/completeMultipart? If yes, where am I supposed to get the fileKey, uploadId, etags?
Regenerate
response.json()