laravel - 将 Vuejs 中的 excel 文件发布到 Laravel
问题描述
我想将本地驱动器上的 Excel 文件发布到 Laravel 应用程序中。但是我收到下面的错误消息,我不知道我是没有通过 axios 正确发送文件还是没有在 Laravel 端接收它。
这是我的 Javascript 文件:
// import { LocalStorage } from 'quasar'
import Pusher from 'pusher-js'
import { PythonShell } from 'python-shell'
import axios from 'axios'
const FormData = require('form-data')
const fs = require('fs')
const path = require('path')
const options = {
// mode: 'text',
// pythonPath: 'path/to/python',
// pythonOptions: ['-u'], // get print results in real-time
scriptPath: path.join(__dirname, '/../rpa')
// args: ['value1', 'value2', 'value3']
}
const exportDir = 'C:\\TEMP\\TFMCH\\'
export const rpa = {
tfmch_LX02 (warehouse, filePath, truncate) {
console.log('Updating LX02 on TFMCH')
const URL = 'http://localhost/tfmch_LARAVEL/public/api/' + 'rpa/lx02'
const formData = new FormData()
formData.append('lx02', fs.createReadStream(filePath))
formData.append('truncate', truncate)
const formConfig = {
headers: { 'Content-Type': 'multipart/form-data' }
}
console.log(URL)
console.log(fs.createReadStream(filePath))
// console.log(filePath)
// console.log(formData)
// console.log(formConfig)
axios.post(URL, formData, formConfig)
.then((response) => {
console.log(response.data)
// if (warehouse === 805) {
// rpa.sap_LX02_wh(804, false)
// }
})
.catch((e) => {
console.log(e)
// console.log('error')
})
}
}
这是我的 Laravel API:
Route::post('rpa/lx02', function(Request $request){
ini_set('max_execution_time', 300);
// return response();
if ($request->truncate) {
LX02::query()->truncate();
}
$contents = file_get_contents($request->lx02->path());
// return response($contents);
Excel::import(new LX02Import, $contents);
$config = new Upload;
$config->table_name = 'LX02';
$config->save();
// $deletedRows = lx02::where('sloc', 'LIKE', 'S%')->delete();
return response()->json("Updated");
});
我从 Laravel 收到错误消息:
{
"message": "Call to a member function path() on string",
"exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
"file": "C:\\Users\\Ingo\\Google Drive\\1 - Webapps\\tfmch_LARAVEL\\routes\\api.php",
"line": 458,
"trace": [
解决方案
推荐阅读
- generics - 如何将接受迭代器的函数提升为具有引用参数的泛型并要求该项为 i32?
- r - R:使用 dplyr 和 group_by 找到绝对差异
- laravel - Laravel 中具有静态方法的门面与类
- android - Koin:在不同的模块定义之间传递属性
- c# - 从 Azure Function 中的 azure blob 容器读取八位字节流时出现超时错误
- php - 方法 Illuminate\Database\Eloquent\Collection::addEagerConstraints 不存在 LARAVEL
- parsing - Ply shift/reduce 冲突:悬空 else 和空产品
- android - 通过应用程序在 Google Play 商店中的屏幕截图质量 - 压缩、模糊和损坏
- javascript - 无法解析 HomeInnerComponent Angular 7 的所有参数
- ssis - 执行后的SSIS包