Not able to download IPFS object using 'Get' in infura

I am trying to upload a file on ipfs using infura and trying to retrieve it, but not able to do it.
Please help.

Here is my code in Python:

import requests
import json

files = {
‘file’: (’/Sample-jpg-image-5mb.jpg’),
}

response = requests.post(‘https://ipfs.infura.io:5001/api/v0/add’, files=files)
p = response.json()
print(p[‘Hash’])

params = (
(‘arg’, p[‘Hash’]),
)
requests.get(‘https://ipfs.infura.io:5001/api/v0/get?arg=’+p['Hash’])

Hello @SARVESH_DUBEY and welcome to our community site.

Can you share the response output you get back when you post the file? Are you able to confirm that the file gets uploaded at all?

Hello @wuehler , I am facing the problem of downloading the ipfs object which I uploaded.
After writing the request.get command too I am not able to download anything, but the response code is 200

@wuehler
For the code:

import requests
import json
import os
files = {
‘file’: (‘Sample-jpg-image-5mb.jpg’),
}
response = requests.post(‘https://ipfs.infura.io:5001/api/v0/add’, files=files)
p = response.json()
print p
print(p[‘Hash’])

Response is:
{u’Hash’: u’QmS1eq4nEXi5VHgrHjD9WzU1jZ6miZLcGgpdcwhmwioVSs’, u’Name’: u’file’, u’Size’: u’32’}
QmS1eq4nEXi5VHgrHjD9WzU1jZ6miZLcGgpdcwhmwioVSs

Can you check the method which I have implemented is correctly uploading the file.

I would recommend utilizing a well developed client library to implement your interactions with IPFS. Have you had a chance to look over this client library? https://github.com/ipfs/py-ipfs-http-client

@wuehler Yeah I used ipfshttpclient before using infura. Actually the reason for shifting to infura is to get daemon running of infura than to start my own daemon. And also get free storage of ipfs objects.

You can use the Infura IPFS gateway with the ipfshttpclient library, just point the code at the Infura endpoint rather than your own.

Hi Sarvesh,

I’ve just tested the following based on the example in their docs and it worked fine:

>>> client = ipfshttpclient.connect('/dns/ipfs.infura.io/tcp/5001/https')
>>> res = client.add('mw')
>>> res
{'Name': 'mw', 'Hash': 'QmXixLM5V3LXnEe2tJfHdwe7RBYNYbDrNw8DHYqjczf7R1', 'Size': '11'}
>>> client.cat(res['Hash'])
b'mw\n'

I hope this helps!