如何在kinvey服务器上上传和下载图像

时间:2016-11-02 11:36:35

标签: android kinvey

嘿我在我的Android应用程序中使用下面的代码。它正在kinvey服务器上成功上传图像。但是当我尝试使用kinvey在文件集合下给出的下载链接http://storage.googleapis.com/6e1e6118eb264d42902a4b280cd5aa7b/myFile/abc.jpg打开它时,它显示“此XML文件似乎没有与之关联的任何样式信息。”文档树如下所示。

  <Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>
     </Error>

当我尝试下载该文件时,它显示未找到blob,我不知道问题出在哪里,请你指出来,我已经给出了下面的下载日志.... 提前谢谢

这是我的图片上传代码

public void  upload()
{
    try{
        File file = new File(""+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/aa.jpg");
        FileMetaData metadata = new FileMetaData("myFile");
        //     metadata.setAcl((new KinveyMetaData()).AccessControlList().setGloballyReadable(true)); //create the FileMetaData object
        metadata.setPublic(true);  //set the file to be pubicly accesible
        //  metadata.setAcl((new KinveyMetaData.AccessControlList()).setGloballyReadable(true)); //allow all users to see this file
        metadata.setFileName("abc.jpg");

        FileInputStream fin=new FileInputStream(file);
        UploaderProgressListener upl=new UploaderProgressListener() {
            @Override
            public void onSuccess(Void result) {
                System.out.println("upload success!");
            }
            @Override
            public void onFailure(Throwable error) {
                System.out.println("upload progress change!");
            }
            @Override
            public void progressChanged(MediaHttpUploader uploader) throws IOException {
                System.out.println("upload progress change -> " + uploader.getUploadState());
            }
        };
        mKinveyClient.file().upload(metadata,fin,upl);
    }catch(Exception e){
        System.out.println("Couldn't upload! -> " + e);
        e.printStackTrace();
    }
}

这是我下载代码的图片

public void download() {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/aa11.jpg");
    try {
        FileOutputStream fos = new FileOutputStream(file);

        DownloaderProgressListener dpl=new DownloaderProgressListener() {
            @Override
            public void progressChanged(MediaHttpDownloader mediaHttpDownloader) throws IOException {
                System.out.println("progress updated: "+mediaHttpDownloader.getDownloadState());
            }

            @Override
            public void onSuccess(Void aVoid) {
                System.out.println("successfully download file");
            }

            @Override
            public void onFailure(Throwable throwable) {
                // System.out.println("failed to download file :->"+throwable.getCause());
                System.out.println("failed to download file :->"+throwable.getLocalizedMessage());
                System.out.println("failed to download file :->"+throwable.getStackTrace());

            }
        };
        Query myQuery=new Query();
        myQuery.equals("id","myFile");
        client.file().download(myQuery,fos,dpl);
    }catch(Exception e)
    {
        System.out.println("in catch block,could'nt download file ---->"+e.getMessage());
    }
}

登录下载图片代码....,下载我发现“blob not found”请查看日志....

  

16:09:46.0​​36 13008-13008 / com.kinvey.sample.statusshare I / System.out:   要在aa1.jpg下载新文件            11-02 16:09:46.0​​51 13008-13341 / com.kinvey.sample.statusshare I / System.out:进度已更新:DOWNLOAD_IN_PROGRESS           11-02 16:09:46.0​​51 13008-13341 / com.kinvey.sample.statusshare I / System.out:进度更新:INITIATION_STARTED             11-02 16:09:46.870 13008-13341 / com.kinvey.sample.statusshare I / System.out:无法下载文件: - &gt;             11-02 16:09:46.870 13008-13341 / com.kinvey.sample.statusshare I / System.out:REASON:BlobNotFound             11-02 16:09:46.870 13008-13341 / com.kinvey.sample.statusshare I / System.out:FIX:找不到此app后端的blob              11-02 16:09:46.870 13008-13341 / com.kinvey.sample.statusshare I / System.out:说明:   正在下载的文件不存在。              11-02 16:09:46.890 13008-13341 / com.kinvey.sample.statusshare I / System.out:未能   下载文件: - &gt; [Ljava.lang.StackTraceElement; @ 33e9dd19

1 个答案:

答案 0 :(得分:0)

加布里埃尔,

  1. 您使用的是哪个版本的Android SDK?
  2. 你是否一直看到其他文件上传/下载的这个问题,或者有时只是发生?
  3. 您是否随时在上传过程中看到任何错误?
  4. 谢谢, Pranav Kinvey支持