Giter VIP home page Giter VIP logo

Comments (15)

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024 1

In browser.

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024 1

I think that on any error should be run the .catch branch.

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

@VladimirKalachikhin,

Thanks a lot by tell-me.

Can you explain as simulate this error?
I guess that was a problem of us document README, right?

see ya

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024

If server return 404 - I am expecting an error, not complete. I.e. .catch, not .then:

imageToBase64("file_not_exist.png")
    .then(
        (response) => {
        	console.log(response); // PCFET0NUWVBF... - base64 of server 404 response
        }
    )
    .catch( 	// no fired!
        (error) => {
            console.log('Error: '+error); //Exepection error....
        }
    ) 

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

Okay, but you using in NodeJS or browser?

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

ok, in browser you must setting the path, example:

imageToBase64("./file_not_exist.png").then(console.log).catch(console.log);

OR

imageToBase64("https://yourdomain.com/images/JavaScript-logo.png").then(console.log).catch(console.log);

In browser you always using URL.

Do you understood?

see ya.

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024

Sorry for delay.

Ok, if file name begin from "http..." then the .catch are fired on 404. If not (even if the path present) - the .catch not fired on 404. Is it ok?

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

No problem, please send to me one example, is important I comment for you: "This lib just accept https not using http", ok?

This case on web (run in browser)

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024

https://is.gd/97xypC

<!DOCTYPE html >
<html lang="ru">
<head>
   <LINK href="common.css" rel="stylesheet" type="text/css">
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <META http-equiv="Content-Script-Type" content="text/javascript">
   <title>This is a example of image-to-base64</title>
   <script src="image-to-base64.min.js"></script> 
</head>
<body>
<h1>Hello!</h1>
<p>
<img id='image1' src='test/nodejs.png'>
<img id='image2' src='http://mediatheque.rsl.ru/image-to-base64/test/nodejs.png'>

<script>
imageToBase64("http://mediatheque.rsl.ru/image-to-base64/test/nodejs.png")
.then(
    (response) => {
    	alert('1. This is responce ok. Result are '+response.length+'bytes length.');
    }
)
.catch(
    (error) => {
        alert('1. Error');
    }
)

imageToBase64("/image-to-base64/test/nodejs.png")
.then(
    (response) => {
    	alert('2. This is responce ok too. Result are '+response.length+'bytes length.');
    }
)
.catch(
    (error) => {
        alert('2. Error');
    }
)

imageToBase64("test/nodejs.png")
.then(
    (response) => {
    	alert('3. And this responce ok. Result are '+response.length+'bytes length.');
    }
)
.catch(
    (error) => {
        alert('3. Error');
    }
)

imageToBase64("http://mediatheque.rsl.ru/nodejs.png")
.then(
    (response) => {
    	alert('4. This request return 404, but .catch not fired and responce length '+response.length+'bytes.');
    }
)
.catch(
    (error) => {
        alert('4. Error');
    }
)

imageToBase64("mediatheque.rsl.ru/nodejs.png")
.then(
    (response) => {
    	alert('5. This request return 404, but .catch not fired and responce length '+response.length+'bytes.');
    }
)
.catch(
    (error) => {
        alert('5. Error');
    }
)
imageToBase64("/test/nodejs.png")
.then(
    (response) => {
    	alert('6. And this request return 404, and .catch not fired and responce length '+response.length+'bytes.');
    }
)
.catch(
    (error) => {
        alert('6. Error');
    }
)
</script>
</body>
</html>```

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

I tried access yours images and don't possible. So, this probably is a error in your server.
This can be a problem of path or url.

image

You can testing as example below:

imageToBase64("http://mediatheque.rsl.ru/image-to-base64/test/nodejs.png")
.then(
    (response) => {
    	alert('2. This is responce ok too. Result are '+response.length+'bytes length.');
    }
)
.catch(
    (error) => {
        alert('2. Error');
    }
)

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024

Sorry, I don't understand.
The right image url is: "http://mediatheque.rsl.ru/image-to-base64/test/nodejs.png"
The "http://mediatheque.rsl.ru/test/nodejs.png" - is a sample a bad url, this produce 404 server response.

By link above You can see code in action, and see alert number and message. Messages appear not in the order of numbers, of course.

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

No problem, my English is very bad.

Well,

This error occurs because this route (URL) that you try access don't exists in your application.
Your images they are inside path image-to-base64, understood?

I realized that you this using my images of example, do you need on your application put on all images and execute code with path.

from image-to-base64.

VladimirKalachikhin avatar VladimirKalachikhin commented on July 20, 2024

Yes. My case is generate the image file name, and retrieve file by this name. If file exist - display img, if not - do something. I want only one request to server for it.
On this case I do not have way to check "File not exist" situation.

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

Nice, always that don't found file the lib will return a base64. We go improvement the treatment this errors, what do you think?

from image-to-base64.

renanbastos93 avatar renanbastos93 commented on July 20, 2024

Nice, I will create a issue with this treatments for be implemented. For as soon possible to be make.

from image-to-base64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.