gpt4 book ai didi

amazon-web-services - 解析 S3FileAdapter

转载 作者:行者123 更新时间:2023-12-02 03:16:43 24 4
gpt4 key购买 nike

我目前有一个解析服务器部署工作,但每次我上传文件时,它都会使用 GridStore 文件适配器而不是 S3 文件适配器存储它。我的应用 JS 看起来像这样:

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');

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

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

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'somAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
},
filesAdapter: new S3Adapter(
"S31",
"S32",
"bucket-name",
{directAccess: true}
)
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('Make sure to star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

部署后我没有收到任何错误。一切似乎都运行良好。但是,当我上传文件时,它会转到我的 monglab 数据库而不是我的 S3 存储。我需要做其他事情来配置它吗?我使用文档作为引用来配置它:

https://github.com/ParsePlatform/parse-server/wiki/Configuring-File-Adapters

我还注意到在解析服务器存储库中它没有 S3FileAdapter: https://github.com/ParsePlatform/parse-server/tree/master/src/Adapters/Files

任何帮助将不胜感激!

谢谢,

大卫

最佳答案

mLab 数据库不存储文件。它只存储文件的链接。您需要先将文件上传到 S3。如果成功,Parse server 将返回一个文件名,然后将该文件名写入数据库。我使用 curl 命令来检查文件写入。如果有效,则您的设置应该没问题。

curl -X POST \
-H "X-Parse-Application-Id: YOUR-APP-ID" \
-H "X-Parse-REST-API-Key: YOUR-KEY" \
-H "Content-Type: text/plain" \
-d 'Hello, it is me!' \
http://your-parse-server/parse/files/filename.txt

关于amazon-web-services - 解析 S3FileAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36536615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com