What is the right way to consume Blobs via JAVASCRIPTS, HTML5, etc?

Asked

Viewed 41 times

2

I am using Google App Engine BLOBSTORE. I already have some images saved on the server now I would like to consume them via browser (HTML5, JAVASCRIPT etc...) It turns out that I have only the link that apparently is not the image itself, as follows:

https://filiperebollo1986.appspot.com/serve?blob-key=AMIfv967H0sWgJttreCFsuGZ57JmaXCkhFPC4QoHcPPxLBN2JhGkOGsY34rdD4ebvqNtdYfTmf_utULqUjdP_9mkjJQ91jkwkcDMlxlU7PZwrC-r0W-eIa3r8YaTWPKd7hAzuTcftyiUg8Ho2k9g1k4JV4Yx2MzdTwe_HeCHKGCvxnH3sm_WWN0

Note that there is no extension in the URL...

What is the correct way to consume these blobs in the browser? Can I simply use this URL in the IMG SRC parameter?

1 answer

1


Yes you can use with the HTML5 img tag, follow the example:

<div>
  <img src="https://filiperebollo1986.appspot.com/serve?blob-key=AMIfv967H0sWgJttreCFsuGZ57JmaXCkhFPC4QoHcPPxLBN2JhGkOGsY34rdD4ebvqNtdYfTmf_utULqUjdP_9mkjJQ91jkwkcDMlxlU7PZwrC-r0W-eIa3r8YaTWPKd7hAzuTcftyiUg8Ho2k9g1k4JV4Yx2MzdTwe_HeCHKGCvxnH3sm_WWN0" />
</div>

But when it comes to good practices, here are some considerations: There are some good practices to be followed when it comes to serving web images, most consist of optimizing the image itself to decrease its weight, and thus decreasing its size which would result in a shorter time for the user to be able to view it on your site, there is a guide of own google in pt-br to teach on the subject, I will be leaving the link at the end of the reply, besides it is also always indicated the use of a CDN service to serve the images and also use caching strategies.

link to the optimization guide: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/image-optimization?hl=pt-br

  • jsfidle link, with an "executable" example https://jsfiddle.net/brz4g3c1/

  • 1

    But is that best practice? What would be the best way to consume these blobs? Won’t I have performance problems using this url directly? Because I realize it takes a while to load in the browser..

  • changed the answer to contemplate this question, beauty?

  • I’m not seeing the change only the HTML tags as you had responded at the beginning..

  • Opa Felipe, check now.

  • 1

    You mean the URL generated is as much as a *.jpeg type URL?

  • Yes, so that your server sent the content-type of your image in Sponse, it makes no difference, now as for the best type of extension to be used is another story, this is very detailed in this guide that I put, in the case of your image, it is sending the containstype image/png, in general the format that more Performa and has high compatibility with the browser is JPEG, however its quality is lower.

  • I was able to clear your doubts?

  • Perfect, thank you very much!

  • Nothing Felipe, glad I could help, good studies, just be sure to prioritize the relevant comments, mark the answer as useful and the question as solved, so other users can view better, :)

  • In my backend I created a Serve.java plus upload... What is the need to use it if I can consume directly through the URL? And how I can use it via browser, JAVASCRIPT, HTML5.. &#xA;&#xA;public class Serve extends HttpServlet {&#xA; private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();&#xA;&#xA; @Override&#xA; public void doGet(HttpServletRequest req, HttpServletResponse res)&#xA; throws IOException {&#xA; Blobkey blobKey = new Blobkey(req.getParameter("blob-key")); blobstoreService.serve(blobKey, res); } }

  • 1

    In my view given your restrictions, I see no reason for you not to use the URL directly, just remember to upload the optimized images to your google service if you are focusing on performance.

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.