parse-community / parse-server-s3-adapter

AWS S3 file storage adapter for Parse Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File URL not being replaced at runtime

RA-Matt opened this issue · comments

Hi, I'm trying to use an s3 file adapter with my parse-server, and I think I'm experiencing some strange behavior.

URL variables:

PUBLIC_SERVER_URL=http://localhost:1337/parse
PARSE_SERVER_URL=http://localhost:1337/parse

(Note, I've tried this on my production server, which has localhost for PARSE_SERVER_URL and a publicly accessible domain for PUBLIC_SERVER_URL)

Expected:
https://PUBLIC_SERVER_URL/files/FILENAME.png

What I'm seeing:
https://BUCKET_NAME.s3.amazonaws.com/FILENAME.png

Initialization Code:

require('dotenv').config()
let express = require('express');
let ParseServer = require('parse-server').ParseServer;
var S3Adapter = require('@parse/s3-files-adapter');

var s3Adapter = new S3Adapter(process.env.S3_BUCKET, {
    region: process.env.S3_REGION,
    bucketPrefix: '',
    directAccess: false,
    signatureVersion: 'v4',
    globalCacheControl: 'public, max-age=86400'
});

let api = new ParseServer({
    databaseURI: databaseUri,
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
    appId: process.env.APP_ID,
    masterKey: process.env.MASTER_KEY,
    serverURL: process.env.PARSE_SERVER_URL,
    publicServerURL: process.env.PUBLIC_SERVER_URL,
    clientKey: process.env.CLIENT_KEY,
    filesAdapter: s3Adapter,
    fileKey: process.env.FILE_KEY,
    verbose: true,
    appName: 'MyApp',
    maxUploadSize: '300mb',
});

Versions:
"parse-server": "4.3.0"
"@parse/s3-files-adapter": "1.6.0"

Any insight as to what I may be doing wrong would be greatly appreciated. All of my file downloads are failing with a 403, but my uploads seem to be working. I'm not sure what the cause of that could be other than the url not being generated correctly at runtime.

Turns out this issue was caused by a remaining environment variable S3_DIRECT_ACCESS=false. The value false was being loaded as a string ("false") which was evaluating to true and treating it as a direct access url.