Mongodb 用cURL上传文件
早上好 我想知道是否有办法将文件从我的桌面上传到GridFS商店中的Meteor服务器 以下是我为创建应用程序而安装的软件包:Mongodb 用cURL上传文件,mongodb,meteor,gridfs,Mongodb,Meteor,Gridfs,早上好 我想知道是否有办法将文件从我的桌面上传到GridFS商店中的Meteor服务器 以下是我为创建应用程序而安装的软件包: accounts-base 1.1.3 A user account system accounts-password 1.0.6 Password support for accounts accounts-ui 1.1.4 Simple templates to add login widgets to an
accounts-base 1.1.3 A user account system
accounts-password 1.0.6 Password support for accounts
accounts-ui 1.1.4 Simple templates to add login widgets to an app
autopublish 1.0.2 Publish the entire database to all clients
cfs:gridfs 0.0.31 GridFS storage adapter for CollectionFS
cfs:standard-packages 0.5.4 Filesystem for Meteor, collectionFS
ian:bootstrap-3 3.3.1 HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.
insecure 1.0.2 Allow all database writes by default
iron:router 1.0.7 Routing specifically designed for Meteor
meteor-platform 1.2.1 Include a standard set of Meteor packages in your app
nimble:restivus 0.6.2 Create authenticated REST APIs in Meteor 0.9.0+. Setup CRUD endpoints for Collections.
这是我的单文件代码:
var fileStore = new FS.Store.GridFS("fileStore");
Files = new FS.Collection("Files", {
stores: [fileStore]
});
if (Meteor.isClient) {
Template.demo.helpers({
files: function() {
var objs = Files.find();
return Files.find();
}
});
Template.demo.events({
'change #file': function(e, t) {
var file = t.find('#file').files[0];
console.log(file.name);
var newFile = new FS.File(file);
newFile.metadata = {
fn: "filename"
};
Files.insert(newFile, function (err, fileObj) {
if (!err) {
var _fId = newFile._id;
var _fn = file.name;
var _collectionName = newFile.collectionName;
var _basePath = "/cfs/files/";
var _downloadPath = _basePath + _collectionName + "/" + _fId;
FileList.insert({
_id: _fId,
fileName: _fn,
collectionName: _collectionName,
basePath: _basePath,
downloadPath: _downloadPath
});
}
});
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
if (Meteor.users.find({}).count() === 0) {
Accounts.createUser({
email : "user@name.it",
password : "password",
profile : {
//publicly visible fields like firstname goes here
}
});
}
// code to run on server at startup
console.log("Set Restivus");
Restivus.configure({
useAuth: true,
prettyJson: true
});
Restivus.addCollection(FileList);
Files.allow({
insert: function(){
return true;
},
update: function(){
return true;
},
remove: function(){
return true;
},
download: function(){
return true;
}
});
});
}
我试过命令:
curl -v -X POST 'http://localhost:3000/cfs/files/Files/' -F 'file=@"download.jpeg";type=image/jpeg'
这是输出:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /cfs/files/Files/ HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
> Content-Length: 5626
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------955a67d5c4b2f2c4
>
< HTTP/1.1 100 Continue
< HTTP/1.1 501 Not Implemented
< vary: Accept-Encoding
< access-control-allow-origin: http://meteor.local
< access-control-allow-methods: PUT
< access-control-allow-headers: Content-Type
< date: Thu, 12 Mar 2015 14:25:55 GMT
< connection: keep-alive
< transfer-encoding: chunked
* HTTP error before end of send, stop sending
<
* Closing connection 0
你能帮我一下吗,或者举个例子
多谢各位
问候。我很幸运收到了这个包裹。它创建了一个上载端点,您可以将其发布到。正如您的错误所示:
访问控制允许方法:PUT
。你不能发布到那里。我会尽快尝试,我会给你反馈,谢谢。嗨,杰弗里,使用以下命令curl-v-X POST'-H'Content-Type:text/plain;charset=UTF-8'-T“file.txt”我从服务器获取此错误“[错误:错误内容类型标题,未知内容类型:text/plain;charset=UTF-8]”。你能帮我吗?按照软件包中的说明让它正常工作(即使用Meteor模板中的上传表单)。使用该表单提交上传,并查看浏览器开发人员工具的“网络”选项卡以检查Ajax POST请求。这些是您必须在curl请求中复制的头文件。您有一些示例吗?我尝试了你建议的方法,但没有成功。非常感谢。
curl -v -X GET 'http://127.0.0.1:3000/cfs/files/Files/d6DAowcAwZcXTKnJ5'