Skip to content

Commit

Permalink
feat: file mime validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
midhun-mobtexting committed Apr 19, 2024
1 parent 9683724 commit a6a85f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions resources/assets/js/bootstrap/filepond.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function load_app_filepond() {
var options = {
credits: false,
maxFileSize: '500MB',
allowFileTypeValidation:true,
allowFileTypeValidation: true,
server: {
timeout: 99999999,
revert: (uniqueFileId, load, error) => {
Expand Down Expand Up @@ -54,27 +54,34 @@ function load_app_filepond() {
process: function (fieldName, file, metadata, load, error, progress, abort) {
var filepondRequest = new XMLHttpRequest();
var filepondFormData = new FormData();

var formData = new FormData();
formData.append('filename', metadata.fileInfo.filenameWithoutExtension)
formData.append('extension', metadata.fileInfo.fileExtension)
formData.append('prefix', prefix)
formData.append('accept', accept)
formData.append('file', file)

fetch(prefix + '/upload/signed', {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': $('input[name="_token"]').val(),
},
method: 'post',
credentials: 'same-origin',
body: JSON.stringify({
filename: metadata.fileInfo.filenameWithoutExtension,
extension: metadata.fileInfo.fileExtension,
prefix: prefix,
metadata: metadata,
accept: accept,
}),
body: formData,
})
.then(function (response) {
return response.json();
})
.then(function (json) {

if (json.code && json.code == 422){
filepondRequest.abort();
abort();
return notify({type: 'error', text: json.message });
}

if (json.disk == 'local') {
file.inputs = json.inputs;
// append the FormData() in the order below. Changing the order
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Upload/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function forLocal(Request $request): JsonResponse
], 201);
}

public function upload(FileValidationRequest $request): JsonResponse
public function upload(Request $request): JsonResponse
{
abort_unless($request->hasValidSignature(), 401);

Expand Down Expand Up @@ -93,7 +93,7 @@ public function revert(Request $request): array
*
* @return JsonResponse
*/
public function signed(Request $request)
public function signed(FileValidationRequest $request)
{
$disk = config('filesystems.default');
if ($disk == 'local') {
Expand Down

0 comments on commit a6a85f9

Please sign in to comment.