2

Is it possible to upload an audio file using the Quip API?

I see in the documentation the API supports the upload of blob objects. I can't seem to get this to work properly.

I have tried uploading both audio and images to no avil. From what I have read online, you first use the put_blob function to upload the blob- this returns the id and url of the blob. Then use the edit_document function to add the blob url to the document ('thread' in quip terminology).

Running the code below does seem to upload the blob, however it is always in plain text format. When adding the blob url to the document- it shows up as a text string /blob/{thread id}/{blob id} and not the actual file. This makes me think that Quip is not able to parse the blob- perhaps because of formatting?

My hope to it emulate the 'insert file' feature of Quip via the API.

What am I doing wrong here? Some code examples in python would be extremely appreciated.

file_path = #path to audio file

with open(file_path, 'rb') as f:
    audio = f.read()

client = quip.QuipClient(access_token=ACCESS_TOKEN)

audio_blob = client.put_blob(thread_id, audio, name='Test_file')

client.edit_document(thread_id, audio_blob['url'], client.APPEND, 'html')
2
  • What error do you get when the code above executes?
    – barrick
    Jul 27 '20 at 22:15
  • Ah, thank you. I should have specified in the question. I will update the post. I don't get any errors when running the code above. The upload does work, however the API seems to always upload a plain text file of the byte array. The result of edit document adds a plain text string- /blob/{thread id}/{blob id}, and not the actual file. I can download the blob using the url, but again it is always a plain text file Jul 27 '20 at 22:49
1

It seems the solution is to supply the html img tag within the content instead of just the URL string.

You could do something like this:

content = "<img src='%s' >" % audio_blob['url']
client.edit_document(thread_id, content, client.APPEND, 'html')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.