How to use png response in axios get request in react [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i send get request to a url and response is a object that contain a Png file and i just want to know how can i use this png in my react app ?

In general: Don't use axios in the first place. Just assign the URL to an image element:
<img src={your_url} alt={suitable_alt_text} />

This question is a little unclear. You need to state in what way you want to use this data and where you have made the request in your react component.Could you post the full file here and I can give a better answer of how you can do this?
From what I can see you could use this response and use the url returned from the object in the <img /> element by adding the key src={data.url} in the element, but I need see if you are setting state or however you use it to give you a fuller answer.

Related

Strapi v4 REST API :GET image [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
please I am working with the new strapi v4 and... In the old versions of strapi all I needed to do in order to get the image from my collection type was to get it like:
<img src={config.baseURL + product?.productImg?.formats?.thumbnail?.url} />
but when I try to do the same now, it gives me the url address, but the response says
{"data":null,"error":{"status":404,"name":"NotFoundError","message":"Not Found","details":{}}}
Any help?
with strapi v4 u need to manually populate your rest api with images otherwise it's restricted due to security reasons :
localhost:1337/api/posts?populate=*
then you will get images on your endpoint
I realised it. In my config file I had the baseURL as 'localhost:1337/api'. However for images, you must request without the '/api' so the request should be just 'localhost:1337' and then the image route.

What is the fastest way to consume an JSON? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I call a JSON with 7000 objects (I use the JS filter direct in the GET's scope and keep the response in a variable) by GET's axios and as you can see from the image it's taking too long, affecting SEO :(
It's 3 seconds delay!
I've done something:
I packed JSON with gzip
I used minify in the JSON*
I put cookies for 1 year on htacess
I put the direct filter on the GET call
Things I want to do but I am unsure and I need your help:
Use Algolia
Split JSON into parts
Can anyone help me please i can't find the answer is i have been looking for this for months :(((
You can implement pagination on your backend to send JSON in smaller peaces or open an stream to read the JSON string and parse it as it's comes

Check if object is deletable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm at the moment making an angular webapplication with an REST api. I'm having a list of object which I request from my REST api. I've implemented a delete function to delete object from the list with a delete request. What I'd also like to implement is a check function which is able to check those objects before they are deleted if it is even possible to delete them but I don't know how to do this. Does anybody know how to write such a check function?
You'll need 'some other way' to communicate this type of information to a client. Your API could for instance just add a deletable property on the resource, determined by the server.
If you're looking for more of a standards approach, you could also implement an OPTIONS requests that returns an Allow header that contains a list of HTTP methods that the client may execute.

How can I set something to the URL by PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to set something to the URL when the page is loading ... How can I do that?
When you open this URL:
http://stackoverflow.com/questions/38839016/should-i-store-the-result-of-an-function
automatically it will be replaced with this:
http://stackoverflow.com/questions/38839016/should-i-store-the-result-of-an-function-into-an-array
How does SO do that?
Note: I've disabled JavaScript on the browser, still that replacement happens. So it is done by PHP.
It's a simple HTTP redirect. Each question has a slug. When the post slug doesn't match with the slug segment of the url, the HTTP controller redirects the page to the correct route.
You can define many rules about rewriting the url address in apache .htaccess file. There magic happens.
You can look in more detail how to define rewrite rules in .htaccess here.

RESTful Commit to Github file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've been looking for quite some time if it is even possible to do this.
I'd like to make a RESTful POST call with a javascript without the use of a server (node) to send a json object in the request body to update a json file in a github repo triggering a commit/push.
Yes, it's possible to do this using the Github API.
The URL must be something like that:
https://api.github.com/repos/{repositoryName}/contents/{path}
repositoryName is the repository where you want to put your file and path its path within this repository.
Regarding the authentication, you need to follow this link https://developer.github.com/v3/#authentication. I successfully tested with basic auth.
You need then to use an HTTP method PUT with content with the following structure:
{
"message": "a commit message",
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
The field content corresponds to the content of your file encoded with base 64.
Hope it helps.
Thierry

Categories

Resources