sudhanshug
sudhanshug
Explore posts from servers
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
No description
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
I am on rails, there is no concept of file route.
you dont need to register the upload if you are not using any FileRoute
ok this is news, will try that
and you can generate signed url without extra request
I am aware of this but the crypto is not matching with what UT server expects and I gave up and used prepareUpload
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
Okay, I will give you a rundown since you are new on this thread. I am trying to do server uploads and here are the issues I am facing: With v6 uploadFile, the file is uploaded correctly but it is not available immediately, my client receives an empty response when requesting the file (via an <img tag). This is fixed on immediately reloading my page, so I am assuming the lag is ~1sec. With v7 prepareUpload, I will have to generate the signed url, register the upload, and then upload the file (3 calls). Since my use case is server uploads, I do not need a callback and hence want to avoid the upload registration entirely. If i dont register the upload, the PUT request never resolves and the file is stuck in uploading state. Lmk if that makes sense 🙂
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
i tried that and it looks like the PUT request waits till the file-key is registered with UT
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
for my server uploads, i dont want a callback - can i pass nil to callback url and slug in the router-metadata request?
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
I suppose i need to register the upload using the route-metadata endpoint, right? Would've been nice if I didn't have to do that.
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
alright, thanks
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
How is the upload request structured? What are the query params/headers or body I need to send
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
alright, if i get the presigned url using the prepareUpload api - how do i upload the file?
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
ok
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
lol - I have both frontend and backend uploads.
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
but I need to do server uploads
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
i am using v7 sdk, i am using v6 here because the rest api docs didnt have any docs for v7 server upload
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
Can you try a server upload? Create an API that: 1. uploads the file 2. returns the file url Here is how I am uploading the file
response = Faraday.post("https://api.uploadthing.com/v6/uploadFiles") do |req|
req.headers["Content-Type"] = "application/json"
req.headers["X-Uploadthing-Api-Key"] = Rails.application.credentials.uploadthing.api_key
req.headers["X-Uploadthing-Version"] = "7.0.0"
req.body = {
files: [{name: key, size: io.size, type: options[:content_type], customId: key}],
acl: "public-read",
contentDisposition: "inline"
}.to_json
end

raise "Upload failed: #{response.status} #{response.body}" unless response.success?

signed_data = JSON.parse(response.body)["data"].first

url = signed_data["url"]
fields = signed_data["fields"]
file_name = signed_data["fileName"] || "file"
content_type = signed_data["fileType"] || "application/octet-stream"

# Ensure the IO object is at the beginning of the file
io.rewind if io.respond_to?(:rewind)

# Prepare the payload for the multipart form data
payload = fields.merge(
"file" => Faraday::UploadIO.new(io, content_type, file_name)
)

# Create a Faraday connection
connection = Faraday.new(url: url) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end

# Perform the POST request to upload the file
response = connection.post do |req|
req.body = payload
end
response = Faraday.post("https://api.uploadthing.com/v6/uploadFiles") do |req|
req.headers["Content-Type"] = "application/json"
req.headers["X-Uploadthing-Api-Key"] = Rails.application.credentials.uploadthing.api_key
req.headers["X-Uploadthing-Version"] = "7.0.0"
req.body = {
files: [{name: key, size: io.size, type: options[:content_type], customId: key}],
acl: "public-read",
contentDisposition: "inline"
}.to_json
end

raise "Upload failed: #{response.status} #{response.body}" unless response.success?

signed_data = JSON.parse(response.body)["data"].first

url = signed_data["url"]
fields = signed_data["fields"]
file_name = signed_data["fileName"] || "file"
content_type = signed_data["fileType"] || "application/octet-stream"

# Ensure the IO object is at the beginning of the file
io.rewind if io.respond_to?(:rewind)

# Prepare the payload for the multipart form data
payload = fields.merge(
"file" => Faraday::UploadIO.new(io, content_type, file_name)
)

# Create a Faraday connection
connection = Faraday.new(url: url) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end

# Perform the POST request to upload the file
response = connection.post do |req|
req.body = payload
end
It's ruby code, but should be easy to understand. Faraday is a http client library.
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
Huh, but the file is uploaded from our server for sure (because my request only resolves when the upload request resolves). Is there a quick way to know the actual status of the file? I can create a client component which retries when it sees a 202 response, but clearly that is not a proper solution 🙂
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
I have an API which uploads the image and returns the file url on successful upload which is utfs.io/f/<f-key>. My expo frontend tries to render the file using this url but it fails because utfs.io/f/<f-key> returns an empty response with status 202. This is what i mean by "upon upload when I request the file" . I dont know the exact delay but i am seeing the image on a reload post upload. Can you check your backend APIs to see when 202 is returned?
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
if I reload my page, which re-requests the file, it works fine magically - probably you guys take some time to serve the file?
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
No description
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
I've tried everything - using hex hmac signature with and without prefix, using b64 of the binary signature. nothing seems to work (copying your py library / following the uploading files doc)
129 replies
TTCTheo's Typesafe Cult
Created by sudhanshug on 10/21/2024 in #questions
[Rails + UT] /v6/prepareUpload not returning presigned URL
Yo, getting "failed to verify url" error when the client tries to upload the file to the presigned url, how can i debug what's happening. the url in question:
https://sea1.ingest.uploadthing.com/UcOlsqhe264cZXlKZmNtRnBiSE1pT25zaVpHRjBZU0k2T1Rnc0luQjFjaUk2SW1Kc2IySmZhV1FpZlgwPS0tZGIwZGMyYjA1YTI3ZTA2YjdiNWNhZWE1Zjk5ZTgwMDAxY2Y0ZGUwMA==?expires=1730461375000&x-ut-acl=public-read&x-ut-content-disposition=inline&x-ut-file-name=Screenshot+2024-06-03+at+7.56.57%E2%80%AFPM.png&x-ut-file-size=19185&x-ut-file-type=image%2Fpng&x-ut-identifier=72uz6xz82c&signature=c1ef437afc02dbc63886a7c57e763321b079dcc93d9b326f02975842f19c1856
https://sea1.ingest.uploadthing.com/UcOlsqhe264cZXlKZmNtRnBiSE1pT25zaVpHRjBZU0k2T1Rnc0luQjFjaUk2SW1Kc2IySmZhV1FpZlgwPS0tZGIwZGMyYjA1YTI3ZTA2YjdiNWNhZWE1Zjk5ZTgwMDAxY2Y0ZGUwMA==?expires=1730461375000&x-ut-acl=public-read&x-ut-content-disposition=inline&x-ut-file-name=Screenshot+2024-06-03+at+7.56.57%E2%80%AFPM.png&x-ut-file-size=19185&x-ut-file-type=image%2Fpng&x-ut-identifier=72uz6xz82c&signature=c1ef437afc02dbc63886a7c57e763321b079dcc93d9b326f02975842f19c1856
It is probably failing at hmac signature comparison, can you share the code you guys have for comparing signatures
129 replies