Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytes or json with filename without saving it to a temporary file #295

Open
fahadh4ilyas opened this issue Aug 24, 2021 · 1 comment

Comments

@fahadh4ilyas
Copy link

Is there any way to add bytes or JSON data without saving it to a temporary file before adding it to IPFS? I wanna do something like

sample_dict = {
    "some_key": "some_value"
}

client.add_json(sample_dict, filename="some_data.json")

Instead, I have to do this

sample_dict = {
    "some_key": "some_value"
}

with open('some_data.json', 'w') as f:
    json.dump(sample_dict, f)

client.add('some_data.json')
@fahadh4ilyas fahadh4ilyas changed the title Add bytesjson with filename Add bytes or json with filename without saving it to a temporary file Aug 24, 2021
@aturX
Copy link

aturX commented Aug 28, 2021

@fahadh4ilyas I can do it by use a File object, when I use javascript. So I think python can use the same way.

  async function onChange(e) {
    var json = `{ "a": 1 }`;
    var file = new File([json], 'test.json', {
        type: 'application/json'
    });
 
    try {
      const added = await client.add(file)
      const url = `https://ipfs.infura.io/ipfs/${added.path}`
      updateFileUrl(url)
    } catch (error) {
      console.log('Error uploading file: ', error)
    }  
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants