Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Accessing S3 img from plain javascript while using django storages

I have a pretty basic issue am unable to solve. I am serving static files from S3 using Django storages. In my template, I setup img source like this:

"{% static 'fun_share/img/logo/logo.svg' %}"

while having

STATIC_URL = "/static/"

Django storages handle the actual img src "translation", ie becomes https://my-bucket.amazonaws.com/static/fun_share/img/logo/logo.svg?..... So far so good.

Now, I want to change the image src from plain javascript to I different image (logo-2.svg).

What is the best way to handle calling the s3 bucket with proper URL (also considering secrets and keys)?

I would expect

 const logo = document.querySelector(".navbar-brand img");
 logo.src = "/static/fun_share/img/logo/logo-2.svg";

to work, but that does not seem to be the case, as the js call is made to the server itself, not redirected to the s3 bucket.

Any help much appriciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can convert the current source to a URL and then change the pathname to get a URL with the same host, query params, etc

const logo = document.querySelector(".navbar-brand img");
let sourceUrl = new URL(logo.src)
sourceUrl.pathname = '/static/fun_share/img/logo/logo-2.svg'
logo.src = sourceUrl.toString()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!