2 回答
TA贡献1797条经验 获得超4个赞
所以你需要使用 Uppy Dashbord 和 Laravel 下载多个文件
然后你必须取回从前端发送到控制器(在你的后端 Laravel 中)的请求,该控制器将此请求作为 Ajax POST 处理。
这可能看起来像(在 routes.php 作为 POST 添加之后)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UploadFileController extends Controller
{
public function showUploadFile(Request $request) {
$file = $request->file('fotografije');
//Display File Name just for check or do a dd
echo 'File Name: '.$file[0]->getClientOriginalName();
//Move Uploaded File
$destinationPath = 'uploads';
$file->move($destinationPath,$file->getClientOriginalName());
}
}
另外,不要忘记将 crsf 令牌添加到您的 uppy 代码中以避免错误请求。
TA贡献1796条经验 获得超4个赞
你可以这样做
var uppy = new Uppy.Core({
// debug: (...args) => console.debug(`[Uppy] [${getTimeStamp()}]`, ...args),
// warn: (...args) => console.warn(`[Uppy] [${getTimeStamp()}]`, ...args),
// error: (...args) => console.error(`[Uppy] [${getTimeStamp()}]`, ...args),
autoProceed: true,
restrictions: {
maxFileSize: 2000000,
maxNumberOfFiles: 10,
minNumberOfFiles: 1,
allowedFileTypes: ['image/*']
}
});
uppy.use(Uppy.Dashboard, {
target: ".UppyDragDrop",
inline: true,
showLinkToFileUploadResult: false,
showProgressDetails: true,
hideCancelButton: true,
hidePauseResumeButton: true,
hideUploadButton: true,
proudlyDisplayPoweredByUppy: false,
locale: {} });
TA贡献1839条经验 获得超15个赞
你可以这样做
//this function runs after the file is uploaded
uppy.on('upload-success', (file, response) => {
const url = response.uploadURL
//get the name of file
const fileName = file.name
let text = "";
//append the image after form using jquery/javascript
//and you can send your images through form
response.body.data.forEach(function (item, index) {
text += index + ": " + item ;
jQuery('<input>').attr({
type: 'hidden',
id: '',
class: 'product_images',
name: 'filename[]',
value:item
}).appendTo('#form_id');
});
})
- 2 回答
- 0 关注
- 187 浏览
添加回答
举报