[英]File uploads not working in rails
I'm trying to upload files to rails using ng-file-upload. 我正在尝试使用ng-file-upload将文件上传到Rails。 My javascript looks like this... 我的JavaScript看起来像这样...
$upload.upload({
url: 'api/my_resource.json',
data: {
files: files
}
})
console.log("files to upload", files);
... where files
is an array of Files. ...其中files
是files
数组。 The console prints 控制台打印
files to upload [File, File]
When I print the request parameters received by my Rails controller, though, I see this: 但是,当我打印Rails控制器收到的请求参数时,会看到以下内容:
Parameters: {"data"=>"{\"files\":[{},{}]}"}
I seems that the files aren't being transmitted. 我似乎没有传输文件。 Does anyone know what I'm doing wrong? 有人知道我在做什么错吗?
I couldn't get this to work using ng-file-upload. 我不能使用ng-file-upload来工作。 Instead I did it in straight javascript, as per here (single file uploads) and here (multiple files). 取而代之的是,我按照此处 (单个文件上传)和此处 (多个文件)的简单javascript进行操作。
fd = new FormData()
for f in files
fd.append("files[]", f);
$http.post('/api/my_resource.json', fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.