mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
handle files via standard field
This commit is contained in:
parent
013df747d7
commit
d66ef233bf
|
@ -6,6 +6,7 @@ use App\Models\SnipeModel;
|
||||||
use Intervention\Image\Facades\Image;
|
use Intervention\Image\Facades\Image;
|
||||||
use enshrined\svgSanitize\Sanitizer;
|
use enshrined\svgSanitize\Sanitizer;
|
||||||
use App\Http\Traits\ConvertsBase64ToFiles;
|
use App\Http\Traits\ConvertsBase64ToFiles;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
use Storage;
|
use Storage;
|
||||||
|
|
||||||
class ImageUploadRequest extends Request
|
class ImageUploadRequest extends Request
|
||||||
|
@ -92,13 +93,22 @@ class ImageUploadRequest extends Request
|
||||||
\Log::debug('DB fieldname is: '.$use_db_field);
|
\Log::debug('DB fieldname is: '.$use_db_field);
|
||||||
\Log::debug('Trying to upload to '. $path);
|
\Log::debug('Trying to upload to '. $path);
|
||||||
|
|
||||||
\Log::debug($this->file());
|
// ConvertBase64ToFiles just changes object type,
|
||||||
|
// as it cannot currently insert files to $this->files
|
||||||
|
if ($this->offsetGet($form_fieldname) instanceof UploadedFile) {
|
||||||
|
$image=$this->offsetGet($form_fieldname);
|
||||||
|
} else {
|
||||||
if ($this->hasFile($form_fieldname)) {
|
if ($this->hasFile($form_fieldname)) {
|
||||||
|
$image = $this->file($form_fieldname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\Log::debug($image);
|
||||||
|
|
||||||
|
if (isset($image)) {
|
||||||
|
|
||||||
if (!config('app.lock_passwords')) {
|
if (!config('app.lock_passwords')) {
|
||||||
|
|
||||||
$image = $this->file($form_fieldname);
|
|
||||||
$ext = $image->getClientOriginalExtension();
|
$ext = $image->getClientOriginalExtension();
|
||||||
$file_name = $type.'-'.$form_fieldname.'-'.str_random(10).'.'.$ext;
|
$file_name = $type.'-'.$form_fieldname.'-'.str_random(10).'.'.$ext;
|
||||||
|
|
||||||
|
|
|
@ -85,16 +85,13 @@ trait ConvertsBase64ToFiles
|
||||||
|
|
||||||
$uploadedFile = new UploadedFile($tempFilePath, $filename, null, null, true);
|
$uploadedFile = new UploadedFile($tempFilePath, $filename, null, null, true);
|
||||||
|
|
||||||
$body = $this->bodyParametersBag()->all();
|
\Log::debug("Trait: uploadedfile ". $tempFilePath);
|
||||||
Arr::forget($body, $key);
|
$this->offsetUnset($key);
|
||||||
$this->bodyParametersBag()->replace($body);
|
\Log::debug("Trait: encoded field \"$key\" removed" );
|
||||||
\Log::debug("Trait: file field $key replaced:". $request->has($key));
|
|
||||||
|
|
||||||
|
//Inserting new file to $this-files does not work so have to deal this after
|
||||||
$files = $this->uploadFilesBag()->all();
|
$this->offsetSet($key,$uploadedFile);
|
||||||
Arr::set($files, $key, $uploadedFile);
|
\Log::debug("Trait: encoded field \"$key\" inserted" );
|
||||||
$this->uploadFilesBag()->replace($files);
|
|
||||||
\Log::debug("Trait: file field $key inserted:". $request->hasFile($key));
|
|
||||||
|
|
||||||
}, null, false);
|
}, null, false);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue