# Image uploads filling Heroku log output

**URL:** <https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798>\
**Category:** Parse Server 📡\
**Created:** [July 19, 2022, 1:44pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798 "2022-07-19T13:44:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [July 19, 2022, 1:44pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/1 "2022-07-19T13:44:32Z")

</div>

Hello,

We are running parse server on Heroku, and having problem with some log output.  
We use a plugin (paperTrail) to save the logs of Heroku to check errors etc, but every time some images are uploaded, it fills up our daily quota of paperTrail pretty quickly (because it outputs a big binary of image file).

We looked into filtering function of paperTrail, but when an image is uploaded, it starts with generic keyword “app[web.1]”, so we cannot just only filter the logs of image binary output (all the other logs starting with “app[web.1]” is not saved anymore, as expected).

Also, it does not help to filter out “input” because image binary output is too long, so it gets truncated, and right after, the rest of the binary data log is printed out with “app[web.1]” multiple times.

Do you know if there is a way not to log output of images or change the starting words “app[web.1]” only for image output?  
Thanks!

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 19, 2022, 2:17pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/2 "2022-07-19T14:17:40Z")

</div>

Are you running with verbose option set true? I am not sure Parse Server automatically logs out image contents (actually even with verbose true). How are you uploading these images?

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [July 20, 2022, 5:14pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/3 "2022-07-20T17:14:57Z")

</div>

Hello, thanks for your reply!  
We didn’t set “verbose”, so we just tested with “verbose: false” in index.js, but it still shows big logs on heroku when any image is uploaded.  
We upload image by cloud code (to AWS) by something like:

const imageTest = request.params.imageTest;  
var image1= new Parse.File(“image.jpg”, imageTest);  
post.set(“image”, image1);

Do you have any idea why??

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 20, 2022, 7:58pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/4 "2022-07-20T19:58:26Z")

</div>

Yes. You are sending the content of the image as a cloud code function parameter. And that’s why it is being logged. Why don’t you save the file in the client and then just send to the cloud code function the file object? It should fix your problem.

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [July 22, 2022, 1:08pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/5 "2022-07-22T13:08:59Z")

</div>

Oh, I see! I tried to find how to do what you suggested: “save the file in the client and then just send to the cloud code function the file object”, but could not figure out how to make this work.

From client side (iOS in the following case), we save parse file and set the cloud code parameter as

if let image:UIImage = self.photoView?.image,  
let data:Data = image.jpegData(compressionQuality: 0.95),  
let imageFile:PFFileObject = PFFileObject(data: data){

```
      params["image"] = imageFile

```

}

* * *

Then in the Cloud function,

we receive this Parse file by

const image = request.params.image;

Then, set

newPost.set(“imageTest”, image);

But then we get error: “Cannot read properties of undefined (reading ‘format’)”

during saving the file: await newPost.save(null, { useMasterKey: true });

Would you have some reference how to do this? I guess the way I am passing parse file to cloud code is not correct (since I am still passing the parse file as a cloud code function parameter).

(We used to create Parse.File on client side, and upload it directly to parse server, but now, we turned off all the Class Level Permissions for this collection for security, so we have to go through cloud function to save images.)

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 22, 2022, 2:34pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/6 "2022-07-22T14:34:29Z")

</div>

You have to save the file (your imageFile var) in the client, before calling the cloud function.

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [July 24, 2022, 7:00pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/7 "2022-07-24T19:00:25Z")

</div>

Thanks for your reply!  
I am sorry we still don’t understand how to do what you are suggesting.  
Do you mean we should save the parse file in the local database of the client device?  
(we are saving these image files (PFObjects) to AWS through parse server)  
Could you give me some reference or a few example lines for this?

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 25, 2022, 3:46pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/8 "2022-07-25T15:46:22Z")

</div>

You need to call `imageFile.saveInBackground()` before calling the cloud code function passing the `imageFile` as parameter. Would you mind to share the code that you are using including the cloud code function call?

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [July 26, 2022, 7:58am UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/9 "2022-07-26T07:58:45Z")

</div>

> [@davimacedo](#):
>
> `imageFile.saveInBackground()` b

Hello,

Thanks for your reply!!

=====================================================  
What we have been doing is the following:  
(This works fine, except we have the big binary logs on Heroku.)

From client device (iOS), we pass parameter as:

```auto
if let image:UIImage = self.photoView1?.image,
    let data:Data = image.jpegData(compressionQuality: compressionQL)
   {
                    params["image1"] = data

//Then we call cloud function "newPostFun"

PFCloud.callFunction(inBackground: "newPostFun", withParameters: params, block: { (result: Any?, error: Error?) -> Void in

```

* * *

In the cloud code function:

```auto
Parse.Cloud.define("newPostFun", async (request) => {

   const image1 = request.params.image1;
   var newPost = new Parse.Object('Post');
   
  
    var image1PF= new Parse.File("image.jpg", image1);
     newPost.set("image1", image1PF);
      

   //... set other parameters as well ...

   await newPost.save(null, { useMasterKey: true });

});

```

This works fine (except we get big binary heorku logs that fills up paperTrail).

=====================================================  
What we have tried now, after adding a line " imageFile.saveInBackground() " is:

From client device (iOS), we pass parameter as:

```auto
 if let image:UIImage = self.photoView1?.image,
     let data:Data = image.jpegData(compressionQuality: 0.95),
      let imageFile:PFFileObject = PFFileObject(data: data)
       {
                    imageFile.saveInBackground() 
                    params["image1"] = imageFile

//Then we call cloud function "newPostFun" (the same as before)

PFCloud.callFunction(inBackground: "newPostFun", withParameters: params, block: { (result: Any?, error: Error?) -> Void in

```

* * *

In the cloud code function:

```auto
Parse.Cloud.define("newPostFun", async (request) => {

   const image1PF = request.params.image1;

   var newPost = new Parse.Object('Post');

   newPost.set(“image1”, image1PF);

   //... set other parameters as well ...

   await newPost.save(null, { useMasterKey: true });

});

```

This gives error on Heroku at the last line while trying to save the Post object,` "await newPost.save(null, { useMasterKey: true });"`

2022-07-26T07:23:07.72307+00:00 app[web.1]: error: Cannot read properties of undefined (reading ‘format’) {“code”:141,“stack”:“TypeError: Cannot read properties of undefined (reading ‘format’)\n at ParseFile.save (/app/node\_modules/parse-server/node\_modules/parse/lib/node/ParseFile.js:375:24)\n at /app/node\_modules/parse-server/node\_modules/parse/lib/node/ParseObject.js:3088:30\n at Array.forEach ()\n at Object.save (/app/node\_modules/parse-server/node\_modules/parse/lib/node/ParseObject.js:3086:15)\n at ParseObject.save (/app/node\_modules/parse-server/node\_modules/parse/lib/node/ParseObject.js:1817:23)\n at /app/cloud/main.js:1776:17\n at processTicksAndRejections (node:internal/process/task\_queues:96:5)”}

On the client side, the error is  
“Cannot read properties of undefined (reading ‘format’)”

=====================================================

Do you see some obvious mistake we are making??

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 26, 2022, 2:14pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/10 "2022-07-26T14:14:23Z")

</div>

Yes. You should await the saveInBackground to complete before calling the cloud code function. Something like this:

```auto
imageFile.saveInBackground({ (success: Bool, error: Error?) in
    // Handle success or failure here ...
   params["image1"] = imageFile
   PFCloud.callFunction(inBackground: "newPostFun", withParameters: params, block: { (result: Any?, error: Error?) -> Void in
})

```

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [September 8, 2022, 2:15pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/11 "2022-09-08T14:15:49Z")

</div>

Hello,  
Sorry, for the slow reply.  
Yes, that seems to work.  
Thanks so much!!

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [September 12, 2022, 8:08pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/12 "2022-09-12T20:08:05Z")

</div>

> [@davimacedo](#):
>
> `imageFile.saveInBackground({`

Actually, I have another question related to this…  
When we save the image file on device with

imageFile.saveInBackground({

it takes too much time (more than a couple of seconds per image) to complete, which seems strange, considering it is only saving it on the same device. Could you think of what the cause of this delay?

We are wondering if it tries to access to the remote parse server (on Heroku in our case) first, and it waits until the response comes back (it should fail because our parse server’s CLP setting does not allow to save files this way), and afterwards, it tries to save it locally on the device. Could this be the reason why it takes such a long time to complete “saveInBackground” on device? If so, could you think of any ways avoid this time lag?

Thanks a lot!!

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [September 26, 2022, 3:09pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/13 "2022-09-26T15:09:55Z")

</div>

`saveInBackground` function sends the file to the server.

---

<div class="post-metadata">

**Author:** ![Sumi](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sumi](https://community.parseplatform.org/u/Sumi)\
**Post date:** [September 30, 2022, 6:43pm UTC](https://community.parseplatform.org/t/image-uploads-filling-heroku-log-output/2798/14 "2022-09-30T18:43:06Z")

</div>

Ok, we finally started to understand how this PFFileObject things work. Thanks a lot!!
