Skip to content

S3 File adapter - accessing previous, non-s3 files #6273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Samigos opened this issue Dec 11, 2019 · 12 comments
Closed

S3 File adapter - accessing previous, non-s3 files #6273

Samigos opened this issue Dec 11, 2019 · 12 comments

Comments

@Samigos
Copy link

Samigos commented Dec 11, 2019

We have a mobile app that runs on Parse Server 2.8.4, hosted at DigitalOcean. We were using the default file adapter (GridStoreAdapter) and now we want to use Spaces by DigitalOcean. This is our updated index file:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var path = require('path');
var S3Adapter = require('parse-server').S3Adapter;
var AWS = require("aws-sdk");

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

//Set Digital Ocean Spaces EndPoint
const spacesEndpoint = new AWS.Endpoint('fra1.digitaloceanspaces.com');
//Define S3 options
var s3Options = {
  bucket: 'bucketName',
  baseUrl: 'https://domain.com',
  region: 'fra1',
  directAccess: true,
  globalCacheControl: "public, max-age=31536000",
  s3overrides: {
    accessKeyId: 'accessKey',
    secretAccessKey: ' secretAccessKey',
    endpoint: spacesEndpoint
  }
};

var s3Adapter = new S3Adapter(s3Options);

var api = new ParseServer({
  databaseURI: databaseUri,
  appId: process.env.APP_ID,
  allowClientClassCreation: false,
  masterKey: process.env.MASTER_KEY,
  fileKey: 'fileKey',  
  serverURL: process.env.SERVER_URL,
  publicServerURL: 'http://ip/parse',
  filesAdapter: s3Adapter
});

Everything works great! The files are stored and retrieved properly, except of the old ones! Every image that was stored with the GridStoreAdapter cannot be fetched anymore! Is there anything that can be done in order to be able to view both old and new files?

@Samigos Samigos changed the title S2 File adapter - accessing previous, non-s3 files S3 File adapter - accessing previous, non-s3 files Dec 11, 2019
@dplewis
Copy link
Member

dplewis commented Dec 11, 2019

A PR was submitted just for this purpose.

parse-community/parse-server-s3-adapter#79

I'll do a release right now so that you use it without having to update your server.

You could use parse-files-utils to transfer the files.

@dplewis dplewis closed this as completed Dec 11, 2019
@Samigos
Copy link
Author

Samigos commented Dec 11, 2019

Thank you very much @dplewis ! So what should I do now? I'm kinda lost!

@dplewis
Copy link
Member

dplewis commented Dec 11, 2019

Wait for the 1.4.0 release of the adapter.

Remove var S3Adapter = require('parse-server').S3Adapter;

npm install --save-exact @parse/s3-files-adapter

Add var S3Adapter = require("@parse/s3-files-adapter");

https://github.com/parse-community/parse-server-s3-adapter#usage-with-digital-ocean-spaces

@Samigos
Copy link
Author

Samigos commented Dec 11, 2019

And after that, it will know where each file is? MongoDB or DO Space?

@dplewis
Copy link
Member

dplewis commented Dec 11, 2019

Parse Server doesn't currently allow multiple file adapters. Therefore, I recommended the migration tool.

@Samigos
Copy link
Author

Samigos commented Dec 11, 2019

So wait, I'm confused! Do I have to transfer all the files from Mongo to the DO Space? Wouldn't that PR you mentioned take care of it? (sorry for bothering you, but I really have no idea of how all these work)

Wouldn't that PR you mentioned take care of it?

I mean wouldn't it separate the MongoDB files and the DO files?

@dplewis
Copy link
Member

dplewis commented Dec 11, 2019

A fileAdapter is used to access the files. Since you changed GridStoreAdapter, you can't use it to fetch files anymore from Mongo.

I mean wouldn't it separate the MongoDB files and the DO files?

Yes they will be separated. You could use a workaround to access the mongo files.

@Samigos
Copy link
Author

Samigos commented Dec 11, 2019

You could use a workaround to access the mongo files.

And that would be the PR you're going to release?

@dplewis
Copy link
Member

dplewis commented Dec 11, 2019

@Samigos Sorry I reread your post and misunderstood. The PR #6274 was to support s3 overrides and endpoints but looks like you have that working.

You have to migrate your files if you want to view old and new files.

@Samigos
Copy link
Author

Samigos commented Dec 11, 2019

Ok! Thank you very much!

@Samigos
Copy link
Author

Samigos commented Dec 12, 2019

Hey @dplewis once more 😄I'm sorry for bothering you again, but I'm desperate! I'm stuck in the migration process and there's really not much I could find!

The repo you sent me above, parse-files-utils can it be used to transfer my files to an S3 bucket? If so, how exactly? I started following the guide, but as soon as I hit npm start config.js it failed with the error logs below:

Cannot load /root/parse-files-utils/config.js
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js "config.js"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-12-12T22_35_35_482Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start', 'config.js' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/parse-files-utils/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle [email protected]~start: CWD: /root/parse-files-utils
10 silly lifecycle [email protected]~start: Args: [ '-c', 'node index.js "config.js"' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `node index.js "config.js"`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:915:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /root/parse-files-utils
16 verbose Linux 4.15.0-34-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start" "config.js"
18 verbose node v8.12.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: `node index.js "config.js"`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Any ideas?

@dplewis
Copy link
Member

dplewis commented Dec 12, 2019

That is an old repo. I’d recommend forking it and make changes you need and run it.

The core logic is there on how to get the all files from the Schema and transfer them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants