Start a new topic
Answered

downloading image

i have issue when i drag image to files and need to download it in the app this error happened 



Got an error:  Error Domain=KCSResourceErrorDomain Code=404 "Error downloading file, id='000-006'" UserInfo={NSLocalizedDescription=Error downloading file, id='000-006', NSUnderlyingError=0x104b077b0 {Error Domain=KCSServerErrorDomain Code=404 "This blob not found for this app backend" UserInfo={NSLocalizedDescription=This blob not found for this app backend, NSErrorFailingURLKey=https://baas.kinvey.com/blob/kid_-JRoOx3OCe/000-006, Kinvey.kinveyErrorCode=BlobNotFound, KinveyKit.HTTPMethod=GET, Kinvey.RequestId=1bca9b79ad5240438b0c32537cfb5169, NSLocalizedFailureReason=}}}



any one know how to fix it 


Best Answer

Rami,

1. Can you try hardcoding the query as below with a new file that you uploaded?

 

let attrib = “file_name_here_along_with_extn"
let pngQuery = KCSQuery(onField: KCSFileFileName, withExactMatchForValue: attrib as! NSObject)

 


2. When viewing the File under "Kinvey Console=>Files”, when you click on the “Download Link” does it open the file in the browser?

I just retried the entire process once again and it just works fine at my end.


Thanks,

Pranav

Kinvey Support


Rami,

I have few questions for you.

  • Do you see the file properly uploaded under “Files” in the Kinvey Console and its file_id?
  • Is the file id that you are passing to the downloadxxx function correct? Can you verify that?
  • How are you downloading the file? Can you try with the sample code provided below and let me know?


// Download File : Method 1 (using file_name of uploaded file)

let attrib = “xxxxx.jpg"

let pngQuery = KCSQuery(onField: KCSFileFileName, withExactMatchForValue: attrib as! NSObject)
       
              KCSFileStore.downloadFileByQuery(pngQuery,
                                         requestConfiguration: nil,
                                         completionBlock: { (downloadedResources: [AnyObject]!, error: NSError!) -> Void in
                                            if error == nil {                                           
                                               
                                                //extract just the Value field from the entities
                                                                                             
                                                let file = downloadedResources[0] as! KCSFile
                                               
                                                let fileURL = file.localURL
                                                let image = UIImage(contentsOfFile: fileURL.path!)
                                                //self.imgView2.image = image                                          
                                               
                                            } else {
                                                print("Got an error: ", error)
                                            }
            },
                                         progressBlock: nil
        )



// Download File : Method 2 (using file_id of uploaded file)

KCSFileStore.downloadData(“file_id_here”,
                                         requestConfiguration: nil,
                                         completionBlock: { (downloadedResources: [AnyObject]!, error: NSError!) -> Void in
                                            if error == nil {
    
                                                //extract just the Value field from the entities
                    
                                                let file = downloadedResources[0] as! KCSFile
                          let image = UIImage(data: file.data!)
                                                                                      
                                                //self.imgView2.image = image
                                                                                              
                                            } else {
                                                print("Got an error: ", error)
                                            }
            },
                                         progressBlock: nil
        )



Thanks,

Pranav

Kinvey Support

 

this the error i get 


Got an error:  Error Domain=KCSResourceErrorDomain Code=404 "Download from GCS Failed" UserInfo={NSErrorFailingURLKey=https://storage.googleapis.com/20556c71cf5740b595ac2f818ec9363d/180a9bf2-6458-4668-bd35-5b7da5bdd092/000-006, NSLocalizedDescription=Download from GCS Failed, NSLocalizedFailureReason=<?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message></Error>}






and this the code i use 







    func Down2Rest( Name4Rest : String )

 

    {

 

 

 

        let pngQuery = KCSQuery(onField: KCSFileFileName , withExactMatchForValue: Name4Rest as NSObject)

 

 

 

 

 

 

        KCSFileStore.downloadFileByQuery(pngQuery,completionBlock: { (downloadedResources: [AnyObject]!, error: NSError!) -> Void in

 

            if error == nil {

 

                //extract just the Value field from the entities

 

 

                let file = downloadedResources[0] as! KCSFile

 

 

                let fileURL = file.localURL

 

 

                let image = UIImage(contentsOfFile: fileURL.path!) //note this blocks for awhile

 

                self.Img_Rest.image = image

 

 

            } else {

                print("Got an error: ", error)

            }

            },progressBlock:{ (objects: [AnyObject]!, percentComplete: Double) -> Void in

 

                print(percentComplete)

 

        })

    }

}



i am using the name filed 

the file is up loaded by drag and drop and i am sure that the name is correct ??


the code i used its working fine with me when i upload the image from the app and then downloaded 

but when i add the image to the Files by drag and drop the download code won't work ?

Rami,


When you drag-drop the file, do you check the “Should this file be publicly readable?” option?
Which browser are you using?
Can you send me a Kinvey console snapshot of the “Files” for this particular file in question that would show the _acl, _public, _requiredHeaders field?


Thanks,

Pranav

Kinvey Support

Pranav, 


 yes i am sure that the option been choose , i am using safari Web browser 


the file name 000-006 


as i mentioned before when i upload the image through the app then download its working fine with the same code 


but when i request the download with drag and drop won't work .


Thanks, 


Answer

Rami,

1. Can you try hardcoding the query as below with a new file that you uploaded?

 

let attrib = “file_name_here_along_with_extn"
let pngQuery = KCSQuery(onField: KCSFileFileName, withExactMatchForValue: attrib as! NSObject)

 


2. When viewing the File under "Kinvey Console=>Files”, when you click on the “Download Link” does it open the file in the browser?

I just retried the entire process once again and it just works fine at my end.


Thanks,

Pranav

Kinvey Support

Pranav, 


thanks for your reply , i will check today and reply , but regarding to the question 2 its does not open any page .


Thanks 

Pranav, 


 Thank you its working fine with me i was missing the extn of the image , i hop you can support mw with my last add inquiry about down loading multi images .


Thanks,

Rami,

Glad that its working for you. I will look into the other ticket as well.

Thanks,
Pranav
Kinvey Support

 

Login or Signup to post a comment