[Files-Module] - Issues using Anomaly\FilesModule\File\FileUploader
Created 7 years ago by edster

I'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  —  7 years ago Best Answer
$uploaded = new UploadedFile(
    $image,
    $slug . '_' . $i . '.jpg',
    'image/jpeg',
    filesize($image),
    null,
    true
);
edster  —  7 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;
        }
    }
piterden  —  7 years ago Best Answer
$uploaded = new UploadedFile(
    $image,
    $slug . '_' . $i . '.jpg',
    'image/jpeg',
    filesize($image),
    null,
    true
);