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

232
Views
Vue.js read blob as object/string to app-variable

I have a vue app with

data: function() {
    return {
        modules: [],
        ...

And method:

methods: {
    submitted: function(){
        ...
        axios({method: 'get',
              url: 'http://' + document.location.host + '/api/execute?commands=' + encodeURI(JSON.stringify(commands)),
              responseType: "blob"}).then(response => {
            
            if (response.headers['content-type'] === 'image/jpeg'){
                this.modules[current]['results']['image']['visible'] = true
                this.modules[current]['results']['text']['visible'] = false
                
                const url = window.URL.createObjectURL(response.data)
                this.modules[current]['results']['image']['value'] = url
            }
            else{
                this.modules[current]['results']['image']['visible'] = false
                this.modules[current]['results']['text']['visible'] = true
                var reader = new FileReader();
                reader.onload = function(e) {
                   // reader.result contains the contents of blob as a typed array
                   console.log(e)
                   this.modules[current]['results']['text']['value'] = reader.result
                }
                reader.readAsArrayBuffer(response.data);
                
            }
            ...

This should request some data from server and show it as text or image depending on server response.

*v-for module in modules earlier*
<div class="resultText" :visibility=module.results.text.visible>
    {{ module.results.text.value }}
</div>
<div class="resultImage" :visibility=module.results.image.visible>
    <img :src=module.results.image.value>
</div>

But the method gives js error when text returned: TypeError: this.modules is undefined
The error in this string:

this.modules[current]['results']['text']['value'] = reader.result

With images it works fine.
With self.modules it gives same: TypeError: self.modules is undefined

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

0

Solved the problem with:

response.data.text().then(text => {
    this.modules[current]['results']['text']['value'] = text
});
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!