formData に image を入れてデータを送る場合
@FrontEnd
const formData = new FormData()
formData.append("image", BLOB_IMAGE_DATA)
axios({
method: 'post',
url: 'SERVER_URL',
data: formData,
config: { headers: {'Content-Type': 'multipart/form-data' }}
})
.then(function (response) {
//handle success
console.log(response);
})
.catch(function (response) {
//handle error
console.log(response);
});
@BackEnd
use Illuminate\Http\Request;
public function upload(Request $request) {
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
https://stackoverflow.com/questions/47630163/axios-post-request-to-send-form-data