Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Different multicoded after migrating to api v3 #68

Unanswered
bogdan asked this question in Q&A
Discussion options

I migrated to upload api v3.
After that, all my files CIDs are bafkr* while legacy api generated bafkr* for text files and bafyb* for binary files.

That is the reason for a change?
What are side effects?
Can I maintain old behavior?

My code:

 url = URI.parse("https://uploads.pinata.cloud/v3/files")
 io = StringIO.new(io) if io.is_a?(String)
 # Form data
 form_data = [
 ["network", network],
 ["name", key],
 ["group_id", @group_id],
 ["keyvalues", JSON.generate(key:)],
 ['file', io, { filename: "file" }]
 ]
 req = Net::HTTP::Post.new(url)
 req["Authorization"] = authorization_header
 req.set_form(form_data, "multipart/form-data")
 http = Net::HTTP.new(url.host, url.port)
 http.use_ssl = true
 res = Errors.retryable(interval: 3) do
 http.request(req)
 end
 unless res.is_a?(Net::HTTPSuccess)
 raise ActiveStorage::IntegrityError, "Upload failed: #{res.code} #{res.body}"
 end
 JSON.parse(res.body).dig("data", "cid")
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /