FIx you github account on Laracasts profile. Use only username and not full url.
May 7, 2021
5
Level 8
Checking if file being uploaded is unique
Hey Folks,
I am building a feature which allos the users to upload files through Trix editor. So people could paste snapshots as well as drag and drop files into the editor. I then process this and upload it on S3 bucket.
Can someone let me know how I can check that the file (not just the name but content) is unique before I upload it to S3
My client side code is this
document.addEventListener("trix-attachment-add", function(event){
var attachment = event.attachment;
console.log(attachment.file)
if (attachment.file)
{
var file=attachment.file;
let formData = new FormData();
formData.append("attachments", file);
axios.post('/fileuploads', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response=>{
this.response_message=response;
attachment.setAttributes({
url: this.response_message['data']['data'],
href: this.response_message['data']['data']
});
}, (error) => {
})
}
}); // Listen to the changes on the
And server side is this
Route::post('/fileuploads', function() {
$fileUploadResponse=request()->file('attachments')->store('problems/'.\Auth::id(),'s3');
$url = Storage::url($fileUploadResponse);
return response()->json(['isvalid'=>true,'data'=>$url ,'message'=>'File uploaded successfully.']);
});
I am ok to do that validation either on client or server. I don't have a preference. Any help is very appreciated.
Please or to participate in this conversation.