0

i have an file encoded in base64 and when i decode it and dump with dd() in laravel and it shows the file name and type so i was wondering where laravel stores this since you cant get it from an base64 encoded file

My frontend javascript https://sourceb.in/ShOZspqBqA i know it does not look that nice

$files = json_decode($attributes['files']);
foreach ($files as $file) {
    $binary = base64_decode($file);
    dd($binary);
    $uuid = Str::uuid();
    Storage::disk('local')->put($uuid,  $binary);
}
  • Why are you using `json_decode`, `base64_decode` etc, when you have [`$request->file`](https://laravel.com/docs/9.x/requests#files) or [`Storage`](https://laravel.com/docs/9.x/filesystem#introduction)? – matiaslauriti Apr 21 '22 at 21:38
  • Hi, @matiaslauriti i did not know about the file helpers if i understand you correctly i can feed it an json formated array of base64 and it will just grap the file without any decodeing? –  Apr 21 '22 at 22:01
  • I do not fully understand what you are trying to do – matiaslauriti Apr 22 '22 at 01:58
  • @matiaslauriti i send from the frond end an Json formatted file array to the backend and now I need to save the files in the storage and save the path to the db but to save the files I need to know the extension and when I do die dump it says the file name and extension while this is not stored in the binary of the file so i was wondering how i would be able to find out what the extension is so i can append it to the file name to store it –  Apr 22 '22 at 13:22
  • I am sorry, but you will have to add an example, as I am not sure what schema you have, what data it has, and more debugging stuff, could you add that to your question? – matiaslauriti Apr 22 '22 at 17:32
  • @matiaslauriti as requested i added my frontend js to my question –  Apr 22 '22 at 18:11
  • your link does not have what `convertToJson` is/means. so I have no idea about the content/schema. – matiaslauriti Apr 23 '22 at 00:37
  • @matiaslauriti my fault still had the wrong link on clipbord while editing now it sould also contain the convert script –  Apr 23 '22 at 16:14
  • Thank you for adding the missing part. I had a look and I am a little bit ignorant about JS (at least for what you are doing), so my question is why are you `base64` encoding the files instead of using a "form" (method of sending data, not a literal UI form)? For example, [this SO answer](https://stackoverflow.com/a/24939229/1998801) shows how to create a `FormData` and send it using AJAX, so you use `$request->file(...)` as I mentioned in my first comment. – matiaslauriti Apr 23 '22 at 21:57
  • @matiaslauriti Do you by any change know how to do it that way in vanilla javascript realy dont want to use Jquery –  Apr 25 '22 at 22:42
  • You will have to google that. I did and found this [SO answer](https://stackoverflow.com/a/46642899/1998801) but I am not sure if it will help you or not – matiaslauriti Apr 25 '22 at 23:26

0 Answers0