Reputation: 3592
I managed to upload an image but don't understand how I can get its URL.
I'm using reactjs. My jsx:
import Strapi from 'strapi-sdk-javascript/build/main';
const apiUrl = process.env.API_URL || 'http://localhost:1337'
const strapi = new Strapi(apiUrl);
<form onSubmit={this.uploadFile}>
<input ref={form=> this.form= form} type="file" name="files"/>
<input type="submit" value="Submit"/>
</form>
And the function:
uploadFile = async (e) => {
e.preventDefault();
let a = new FormData(this.form);
const response = await strapi.upload(a);
The file is being uploaded but the response just receives the value of true, and I'm not getting a full response.
I tried to understnad strapi docs but didn't understand how to implement it: https://strapi.io/documentation/3.x.x/guides/upload.html#examples
Thanks a lot in advance
Upvotes: 2
Views: 8932
Reputation: 21
The base URL to assess the images uploaded to Strapi is http://localhost:1337 if you are working in the development environment.
Upvotes: 1
Reputation: 582
When uploading a file, you would normally get a response like this:
{
"id": 5,
"name": "key.jpg",
"hash": "045a33af53ad4efe9dd0cdc80173e792",
"sha256": "hLIpLA5JHEKfjfnAhgr9HqvKpNkm1QH1J-kvrIkGogQ",
"ext": ".jpg",
"mime": "image/jpeg",
"size": "4238.72",
"url": "/uploads/045a33af53ad4efe9dd0cdc80173e792.jpg",
"provider": "local",
"public_id": null,
"created_at": 1551723193383,
"updated_at": 1551723193411,
"related": [
]
}
Upvotes: 3