[Files-Module] - Issues using Anomaly\FilesModule\File\FileUploader
Created 6 years ago by edsterI'm trying to use Anomaly\FilesModule\File\FileUploader
but it is throwing the most useless validation error of validation.uploaded
MessageBag {#3899 ▼
#messages: array:1 [▼
"file" => array:1 [▼
0 => "validation.uploaded"
]
]
#format: ":message"
}
If you remove line 99 it works just fine. I have no mime restrictions set.
I have no idea why it is throwing this, any input much appreciated.
My method currently
public function handle(FileUploader $save, FolderRepositoryInterface $folder)
{
$raw = file_get_contents($this->downloadLink);
if (file_put_contents($this->path,$raw)){
$tmp = new UploadedFile($this->path, $this->fileName);
$file = $save->upload($tmp, $folder->findBySlug('strata_documents'));
dd($file);
} else{
return FALSE;
}
}
piterden
—
6 years ago
Best Answer
Link
edster
—
6 years ago
Ok figured it out, turns out because it wasn't an actually uploaded file (via post) I have to flag the UploadedFile
as a "test"
Finished class below, @ryanthompson is there no better way to tackle this? I would have thought there would be a method in files module where you can pass the external URL and the folder you want it to save to, and it will save it.
public function handle(FileUploader $save, FolderRepositoryInterface $folder, Filesystem $filesystem)
{
$raw = file_get_contents($this->downloadLink);
if (file_put_contents($this->path, $raw)) {
$tmp = new UploadedFile($this->path, $this->fileName, NULL, NULL, NULL, TRUE);
$file = $save->upload($tmp, $folder->findBySlug('strata_documents'));
$filesystem->delete($tmp->getRealPath());
return $file;
} else {
return FALSE;
}
}