tv2regionerne / statamic-private-api

MIT License
3 stars 2 forks source link

Asset upload does not seem to work #20

Closed sdussaut closed 2 months ago

sdussaut commented 2 months ago

Hi!

I am trying to upload an asset through the private API and I get a weird error with no details whatsoever to understand where it is failing.

I send this request: /api/private/asset-containers/assets/assets with a folder field set to / and a file_url set. The request fails and sends a 422 Unprocessable Content code with the following message:

"errors": {
    "file": [
        "The file failed to upload."
    ]
}

What I can see is that the image is successfully created into the tmp folder in storage but then fails at uploading it. There is no trace into the laravel logs either.

Any idea on what could be happening?

Thanks!

SylvesterDamgaard commented 2 months ago

@sdussaut Can you share the request with me? Reading through the code, I can see that there's some potential issues around filenames.

sdussaut commented 2 months ago

Thanks! It works with the new release.

One thing to note though: I was having an error at first with this line specifically file_put_contents(storage_path('tmp/'.$tmpPath), $contents); in /src/Http/Controllers/AssetController.php. It was because the tmp directory in storage did not exists. I check on another Statamic installation I have and it does not exist there either. I am wondering whether a check regarding the existence of this directory should be added too as a safeguard. Once I created it, it worked fine though.

Thanks again for the quick fix!

SylvesterDamgaard commented 2 months ago

Thanks! It works with the new release.

One thing to note though: I was having an error at first with this line specifically file_put_contents(storage_path('tmp/'.$tmpPath), $contents); in /src/Http/Controllers/AssetController.php. It was because the tmp directory in storage did not exists. I check on another Statamic installation I have and it does not exist there either. I am wondering whether a check regarding the existence of this directory should be added too as a safeguard. Once I created it, it worked fine though.

Thanks again for the quick fix!

Thank you for the feedback @sdussaut The tmp path is opiniated and shouldn't be.

I have created a PR which will solve this requirement and just use the build in temp dir in PHP. https://github.com/tv2regionerne/statamic-private-api/pull/24