File upload enableForAuthenticatedUser not working?

Hi,
I’m using the Parse S3 files adapter. All users in my app are logged in and authenticated with Parse using the JS SDK.

Here’s the issue: If I set the following server options:

  fileUpload: {
    enableForPublic: true,
    enableForAnonymousUser: true,
    enableForAuthenticatedUser: true,
  }

All uploads work fine as expected. BUT if I set the public upload to FALSE:

  fileUpload: {
    enableForPublic: false,
    enableForAnonymousUser: true,
    enableForAuthenticatedUser: true,
  }

I get the error: File upload by public is disabled
And none of my in-app uploads work, even though I am passing the user session token to the filesAdapter like so:

await parseFile.save({sessionToken: Parse.User.current().attributes.sessionToken});

Why can’t I disable public file uploads and still allow logged-in users to upload?

Forgive me if you’ve tried this!

If you tail your logs when you make the request, do you see the user object of the authenticated user being included in the request?

Are all your Classes definitely locked down to require authentication (at a minimum)?

If you make requests to other Parse Classes, do you also see the user object in the request?

I’m not seeing the user object in the logs. Should it be there somewhere? Here is what I get:

2022-12-20T19:57:47.370734+00:00 heroku[router]: at=info method=OPTIONS path="/parse/files/test.jpeg" host=myapp.herokuapp.com request_id=... fwd="......." dyno=web.1 connect=0ms service=4ms status=200 bytes=639 protocol=https
2022-12-20T19:57:47.961899+00:00 heroku[router]: at=info method=POST path="/parse/files/test.jpeg" host=myapp.herokuapp.com request_id=... fwd="......." dyno=web.1 connect=0ms service=432ms status=400 bytes=711 protocol=https
2022-12-20T19:57:47.969404+00:00 app[web.1]: error: File upload by public is disabled. {"code":130,"stack":"Error: File upload by public is disabled.\n    at createHandler (/app/node_modules/parse-server/lib/Routers/FilesRouter.js:134:12)\n    at Layer.handle [as handle_request] (/app/node_modules/parse-server/node_modules/express/lib/router/layer.js:95:5)\n    at next (/app/node_modules/parse-server/node_modules/express/lib/router/route.js:137:13)\n    at handleParseHeaders (/app/node_modules/parse-server/lib/middlewares.js:259:5)\n    at Layer.handle [as handle_request] (/app/node_modules/parse-server/node_modules/express/lib/router/layer.js:95:5)\n    at next (/app/node_modules/parse-server/node_modules/express/lib/router/route.js:137:13)\n    at /app/node_modules/parse-server/node_modules/body-parser/lib/read.js:130:5\n    at invokeCallback (/app/node_modules/parse-server/node_modules/raw-body/index.js:224:16)\n    at done (/app/node_modules/parse-server/node_modules/raw-body/index.js:213:7)\n    at IncomingMessage.onEnd (/app/node_modules/parse-server/node_modules/raw-body/index.js:273:7)"}

Also, yes all my Classes are locked down to require authentication.

Sorry, it looks like perhaps the logs I was looking at (which include the user obj are for cloud functions, not regular Parse api calls).

I assume you’re making this request from a client side app? If so, you could perhaps inspect your request in the dev tools network tab.

Else, another quick and dirty debug to check if you are making authenticated requests, is to create a cloud function, call it in the same way and see if your user obj is included.

Correct, I’m trying to allow file uploads from the client side for authenticated users, while keeping it disabled for unauthenticated users.

I do know that for my cloud functions, the user object is automatically included in the request regardless of whichever parameters I send to it. This is working fine for my cloud functions and I can access the user object just fine.

Hi @StatDet,

Sorry for the delayed reply, I took some time off over Christmas.

It’s good to know that you are sending the authenticated user obj along with the request. Unfortunately I’ve not yet worked with Parse Files, so can’t help too much more right now.

I’ll probably try it out this week as I have need for it. If I learn anything useful, I’ll gladly share it here.

Hi @StatDet,

As it turns out, I needed to get Files working in my app sooner than I’d thought, which I did and so came back to your post…

I’m not using the SDK, but rather make use of the rest api. I have not setup any config for the fileUpload property, so I guess it’s using the default, which seems to disallow file uploads.

If I make a post request without my sessionToken, it fails, but if I add it, it works as expected.

Perhaps try using a rest tool like postman or insomnia to test it out. Try removing the filUpload config to see if that makes a difference.

Lastly, also check your Parse version. I started this project some time ago and I had not yet updated it to Parse 5 (this was relevant for me because I’m storing files on CloudFlare’s R2 service - it migth not be relevant for you).

I hope you come right.