lib/active_storage/service/pinata_service.rb
# File is uploaded to Pinata and a hash
# is returned which is used to retrieve the file
# Change the key of the blob to that of the hash
File is uploaded to Pinata and a hash
is returned which is used to retrieve the file
Change the key of the blob to that of the hash
File is uploaded to Pinata and a hash is returned which is used to retrieve the file Change the key of the blob to that of the hash
def upload(key, io, checksum: nil, **)
      instrument :upload, key: key, checksum: checksum do
        data = @client.add io.path
        cid_key = data['IpfsHash']
        if blob_exists?(cid_key)
          existing_blob = find_blob(cid_key)
          new_blob = find_blob(key)
          attachment = Attachment.last
          attachment.update blob_id: existing_blob.id
          new_blob.destroy!
        else
          find_blob(key).update key: cid_key
        end
      end
    end
def upload ( key , io , checksum : nil , ** ) instrument :upload , key : key , checksum : checksum do data = @client . add io . path cid_key = data [ 'IpfsHash' ] if blob_exists? ( cid_key ) existing_blob = find_blob ( cid_key ) new_blob = find_blob ( key ) attachment = Attachment . last attachment . update blob_id : existing_blob . id new_blob . destroy! else find_blob ( key ) . update key : cid_key end end end
File is uploaded to Pinata and a hash
is returned which is used to retrieve the file
Change the key of the blob to that of the hash
File is uploaded to Pinata and a hash is returned which is used to retrieve the file Change the key of the blob to that of the hash
key
<not_specific>
io
<not_specific>
checksum
<not_specific>