在后端使用Laravel尝试上传文件时遇到问题.
Laravel $request->file()
方法返回null.
我使用superagent构建了一个AJAX请求,调试了请求,一切似乎都很好.在Content-Length
根据我在图像上添加的变化,指示图像已被添加到该请求.该Content-Type
也被设置为multipart/form-data
.
// request headers
Content-Length:978599
Content-Type:multipart/form-data;
// request payload
Content-Disposition: form-data; name="files"; filename="item-keymoment.png"
Content-Type: image/png
Run Code Online (Sandbox Code Playgroud)
但是我无法在Laravel中获取该文件.使用$request->file('files')
返回NULL
,但如果我调试$_FILES
数组,我注意到我的文件已上传.
dd($request->file('files'))
// NULL
dd($_FILES);
// array:1 [
// "files" => array:5 [
// "name" => "item-keymoment.png"
// "type" => "image/png"
// "tmp_name" => "/tmp/phpipbeeM"
// "error" => 0
// "size" => 978274
// ]
// ]
dd($request->files->all())
// []
Run Code Online (Sandbox Code Playgroud)
什么可能导致Laravel忽略该文件?
Content-Type
输入文件不是application/octet-stream
? …
我正在构建一个应用程序,我需要在应用程序启动时预加载people
和planet
数据(可能在未来可能会增加更多预加载要求).我希望在商店中拥有代表应用程序全局状态的价值loaded: <boolean>
.当预载值的要求是真实的,只有那么people.loaded: true
和planet.loaded: true
是真实的.商店看起来像这样:
Store
??? loaded: <Boolean>
??? people:
? ??? loaded: <Boolean>
? ??? items: []
??? planets:
? ??? loaded: <Boolean>
? ??? items: []
Run Code Online (Sandbox Code Playgroud)
单独的操作创建者会生成由People
and和Planets
reducers 处理的所需异步请求和调度操作.如下图所示(使用redux-thunk):
actions/index.js
import * as types from '../constants/action-types';
import {getPeople, getPlanets} from '../util/swapi';
export function loadPeople () {
return (dispatch) => {
return getPeople()
.then((people) => dispatch(addPeople(people)));
};
}
export function loadPlanets () …
Run Code Online (Sandbox Code Playgroud) 新的单元测试和间谍,存根和嘲笑的概念.
我想从下面的代码中测试该verify
方法password.js
,但我无法在测试文件中使用stub
该hash
函数.
由于verify
采用了hash
功能和hash
性能输出,不过,我觉得我应该stub
在hash
函数返回,而实际调用一个固定的响应hash
.因为我不是想测试这个hash
功能.
问题:hash
测试时未调用创建的函数存根verify
.
问题1:我应该专注于测试函数本身的逻辑而不是其他被称为函数的逻辑吗?
主要问题:(已 回答)如何在同一模块中调用模块函数?
问题2:hash
如果它没有被导出但只留在模块中,我将如何进行存根?
password.js
/**
* Creates a hash based on a salt from a given password
* if there is no salt a new salt will be generated
*
* @param {String} password
* @param {String} [salt] Optional value, if not given will …
Run Code Online (Sandbox Code Playgroud) javascript ×2
file-upload ×1
laravel ×1
node.js ×1
php ×1
reactjs ×1
redux ×1
sinon ×1
testing ×1
unit-testing ×1