Tuesday 19 February 2019

File Upload

// Client
("Content-type","multipart/form-data; charset=utf-8; boundary=" + Math.random().toString().substr(2));

https://stackoverflow.com/questions/40561738/php-message-warning-missing-boundary-in-multipart-form-data-post-data-in-unknow

            // Add headers
            let headers = {
                'Accept':       'application/json',
                'Authorization': 'Bearer ' + this.jwt_token,
                'Content-type' : 'multipart/form-data; charset=utf-8; boundary=' + Math.random().toString().substr(2)
            };

            // Make form data
            let params = new FormData();
            params.append('file_name', this.upload_data.file_name);
            params.append('shared_with', JSON.stringify(this.upload_data.shared_with));
            params.append('file', this.upload_data.file);

            // Post request
            this.$http.post('api/files/upload', params, {headers: headers})
                .then(response => {
...........
}

https://hayuq.com/blog/articles/189.shtml


// Laravel backend

     
       use Illuminate\Support\Facades\File;
     
        $path = '/home/jxiang/seymour_file_portal_uploads';
        // Create a dir where owner has R/W/E but groups and public only have R/E * because creating at home dir, only created user has R/W/E, user group has E, other has none
        File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);


        $file->move($path, $file->getClientOriginalName());

https://www.tutorialspoint.com/laravel/laravel_file_uploading.htm
https://laravel.com/api/5.3/Illuminate/Filesystem/Filesystem.html

https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/

No comments:

Post a Comment