Cancel Google Drive upload possible?

后端 未结 4 693
长情又很酷
长情又很酷 2020-12-31 13:22

I have written an app using the official API to upload to Google drive, this works perfectly. However I can\'t find anyway to cancel an upload. I\'m running it in an ASync

4条回答
  •  Happy的楠姐
    2020-12-31 14:14

    In a comment I have said that putting the request in a thread and call interrupt is not working. So I was searching another way of doing it.

    I have finally found one, an ugly one: Close the InputStream of the uploaded file!

    I initialize with:

    mediaContent = new InputStreamContent(NOTE_MIME_TYPE,new BufferedInputStream(new FileInputStream(fileContent)));
    mediaContent.setLength(fileContent.length());
    

    And in a stop listener I have :

    IOUtils.closeQuietly(mediaContent.getInputStream());
    

    For sure it should be possible to do it in a better way!

    Regards

提交回复
热议问题