Start a new topic

Post file as public

I tried posting a file as public but when I try to access it I get the message

The specified key does not exist


here is my code(personal info removed)


collectionAccess.collection(objecttype).find({queryValue},function (err, docs) 

  {

    if (err) 

    {

      logger.info(err);

      response.complete(err);

    } 

    else 

    {

      csvString="";

      

      docs.forEach (function (user)

      {

        csvString+="";

        csvString+="";

      });

      

      var jsondocstocsv = docs; // need to convert json to csv here

      var decidedfilename = "log.csv"; // change the filename


      // logger.info(docs.length);

      var uri = 'https://' + request.headers.host + '/blob/'+ appKey;

      var options = 

      {

        "uri" : uri,

        "method": "POST",

        "headers" : 

        {

          "Host": request.headers.host,

          "Content-Type": "application/json",

          "X-Kinvey-API-Version": 3,

          "Authorization": authString,

          "X-Kinvey-Content-Type": "text/csv"

        },

        "json" : {"_filename": decidedfilename,"_public":true, "_acl": {}}

      };

      modules.request.post(options, function(error, res, body)

      {

        if (error) 

        {

          logger.info(error);

          response.complete(error);

        } 

        else 

        {

          var newfileid = body._id;

          logger.info(body._uploadURL);

          var options = 

          {

            "uri" : body._uploadURL,

            "method": "PUT",

            "headers" : 

            {

              "Content-Type": "text/csv",

              "Content-Length": csvString.length

            },

            "body" : csvString

          };

          modules.request.put(options, function(error, res, body)

          {

            if (error) {

              logger.info(error);

              response.complete(error);

            } else {

               //logger.info(res);

               //logger.info(body);

              var uri = 'https://' + request.headers.host + '/blob/'+ appKey + "/" + newfileid;

              var options = {

                "uri" : uri,

                "method": "GET",

                "headers" : {

                  "Host": request.headers.host,

                  "X-Kinvey-API-Version": 3,

                  "Authorization": authString,

                }

              };

              modules.request.get(options, function(error, res, body){

                if (error) {

                  logger.info(error);

                  response.complete(error);

                } else {

                  // logger.info(res);

                  

                  //logger.info(JSON.parse(body)._downloadURL);

                  downloadURL=JSON.parse(body)._downloadURL;

                  modules.email.send('email',

               'email',

           'Join my octacgon in my-app!',

           "Your claim has been subbmitted",

           null,

           '<html><a href='+downloadURL+'>log<a></html>');


                  response.complete(200, "OK");

                }

              });

            }

          });

        }

      });

    }

  });


Thank you please let me know

Hi,


I was able to replicate this issue. If _public flag is set to true, the file is not accessible using the _downloadURL with "The specified key does not exist" error. And if _public flag is set to false or not specified, the _downloadURL works fine.


Let me escalate this internally and I will get back to you with an update.


Regards,

Wani

Kinvey Support

Login or Signup to post a comment