Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38486 > unrolled thread

Testing for blob

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2020-07-07 18:37 +1000
Last post2020-07-08 17:42 +1000
Articles 6 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Testing for blob Andrew Poulos <ap_prog@hotmail.com> - 2020-07-07 18:37 +1000
    Re: Testing for blob "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-07-07 11:33 +0200
      Re: Testing for blob "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-07-07 11:48 +0200
    Re: Testing for blob Julio Di Egidio <julio@diegidio.name> - 2020-07-07 23:44 -0700
      Re: Testing for blob Julio Di Egidio <julio@diegidio.name> - 2020-07-07 23:48 -0700
      Re: Testing for blob Andrew Poulos <ap_prog@hotmail.com> - 2020-07-08 17:42 +1000

#38486 — Testing for blob

FromAndrew Poulos <ap_prog@hotmail.com>
Date2020-07-07 18:37 +1000
SubjectTesting for blob
Message-ID<C9udnaDXJImnqZnCnZ2dnUU7-KPNnZ2d@westnet.com.au>
I have a function

function upload(f) {
   ...
}

if within the function I add

console.log(f, f instanceof Blob);

I get

Blob {size: 16231, type: "audio/mpeg-3"} false

I don't understand how f can be a blob but not be an instance of Blob.

At any rate the deeper problem I have is to be able to distinguish 
whether f is a blob (from new Blob) or a file (from an input of 
type="file").

Andrew Poulos

[toc] | [next] | [standalone]


#38487

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-07-07 11:33 +0200
Message-ID<XnsABF375980BC82eejj99@194.109.6.166>
In reply to#38486
Andrew Poulos <ap_prog@hotmail.com> wrote on 07 Jul 2020 in 
comp.lang.javascript:

> I have a function
> 
> function upload(f) {
>    ...
>}
> 
> if within the function I add
> 
> console.log(f, f instanceof Blob);
> 
> I get
> 
> Blob {size: 16231, type: "audio/mpeg-3"} false
> 
> I don't understand how f can be a blob but not be an instance of Blob.
> 
> At any rate the deeper problem I have is to be able to distinguish 
> whether f is a blob (from new Blob) or a file (from an input of 
> type="file").
> 
> Andrew Poulos

Could be a timing problem, in the sense of "notjet a blob".

So try again later, with a timeout or an onclick.


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38488

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-07-07 11:48 +0200
Message-ID<XnsABF37832AB7C4eejj99@194.109.6.166>
In reply to#38487
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote on 07 Jul 2020 in 
comp.lang.javascript:

> Andrew Poulos <ap_prog@hotmail.com> wrote on 07 Jul 2020 in 
> comp.lang.javascript:
> 
>> I have a function
>> 
>> function upload(f) {
>>    ...
>>}
>> 
>> if within the function I add
>> 
>> console.log(f, f instanceof Blob);
>> 
>> I get
>> 
>> Blob {size: 16231, type: "audio/mpeg-3"} false
>> 
>> I don't understand how f can be a blob but not be an instance of Blob.
>> 
>> At any rate the deeper problem I have is to be able to distinguish 
>> whether f is a blob (from new Blob) or a file (from an input of 
>> type="file").
>> 
>> Andrew Poulos
> 
> Could be a timing problem, in the sense of "notjet a blob".
> 
> So try again later, with a timeout or an onclick.

Or make an "instant" Blob:

var f = new Blob()
console.log(f, f instanceof Blob); // Blob true




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#38489

FromJulio Di Egidio <julio@diegidio.name>
Date2020-07-07 23:44 -0700
Message-ID<e0d526cd-606b-47cd-a131-3761e0da0b1do@googlegroups.com>
In reply to#38486
On Tuesday, 7 July 2020 10:37:24 UTC+2, Andrew Poulos  wrote:
> I have a function
> 
> function upload(f) {
>    ...
> }
> 
> if within the function I add
> 
> console.log(f, f instanceof Blob);
> 
> I get
> 
> Blob {size: 16231, type: "audio/mpeg-3"} false
> 
> I don't understand how f can be a blob but not be an instance of Blob.

Maybe a problem with (how you are using) console.log?

> At any rate the deeper problem I have is to be able to distinguish 
> whether f is a blob (from new Blob) or a file (from an input of 
> type="file").

Check for instanceof File as well.

This seems to work: <http://jsfiddle.net/hjbxanz1/2/>

HTH,

Julio

[toc] | [prev] | [next] | [standalone]


#38490

FromJulio Di Egidio <julio@diegidio.name>
Date2020-07-07 23:48 -0700
Message-ID<bae28b29-37ef-4d19-b439-b78bc8a5d030o@googlegroups.com>
In reply to#38489
On Wednesday, 8 July 2020 08:44:06 UTC+2, Julio Di Egidio  wrote:
> On Tuesday, 7 July 2020 10:37:24 UTC+2, Andrew Poulos  wrote:
> > I have a function
> > 
> > function upload(f) {
> >    ...
> > }
> > 
> > if within the function I add
> > 
> > console.log(f, f instanceof Blob);
> > 
> > I get
> > 
> > Blob {size: 16231, type: "audio/mpeg-3"} false
> > 
> > I don't understand how f can be a blob but not be an instance of Blob.
> 
> Maybe a problem with (how you are using) console.log?
> 
> > At any rate the deeper problem I have is to be able to distinguish 
> > whether f is a blob (from new Blob) or a file (from an input of 
> > type="file").
> 
> Check for instanceof File as well.
> 
> This seems to work: <http://jsfiddle.net/hjbxanz1/2/>
> 
> HTH,

Since I am not sure the fiddle isn't editable, here is the code:

----------------
<p><input type="file" id="infile"></p>

<p><textarea id="output" rows="20" cols="50"></textarea></p>
----------------

----------------
var infile = document.getElementById("infile");
var output = document.getElementById("output");

infile.addEventListener("change", function () {
	var file = infile.files[0];
	var blob = new Blob(["test"], { type: "text/plain" });
	
	output.innerText =
		"file is Blob = " + (file instanceof Blob) + "\n" +
		"blob is Blob = " + (blob instanceof Blob) + "\n" +
		"file is File = " + (file instanceof File) + "\n" +
		"blob is File = " + (blob instanceof File) + "\n" +
		"(" + new Date().toISOString() + ")";
});
----------------

Julio

[toc] | [prev] | [next] | [standalone]


#38491

FromAndrew Poulos <ap_prog@hotmail.com>
Date2020-07-08 17:42 +1000
Message-ID<uoSdncFqW_hF5ZjCnZ2dnUU7-VHNnZ2d@westnet.com.au>
In reply to#38489
On 8/07/2020 4:44 pm, Julio Di Egidio wrote:
> On Tuesday, 7 July 2020 10:37:24 UTC+2, Andrew Poulos  wrote:
>> I have a function
>>
>> function upload(f) {
>>     ...
>> }
>>
>> if within the function I add
>>
>> console.log(f, f instanceof Blob);
>>
>> I get
>>
>> Blob {size: 16231, type: "audio/mpeg-3"} false
>>
>> I don't understand how f can be a blob but not be an instance of Blob.
> 
> Maybe a problem with (how you are using) console.log?

I was creating the blob in one function and passing it to a second 
function. In the second function it didn't recognise f as the blob 
created earlier. I combined the two functions into one and now a blob is 
recognised as a blob.

>> At any rate the deeper problem I have is to be able to distinguish
>> whether f is a blob (from new Blob) or a file (from an input of
>> type="file").
> 
> Check for instanceof File as well.
> 
> This seems to work: <http://jsfiddle.net/hjbxanz1/2/>

Thanks, blob instanceof File - allows me to separate a blob from a file.

Andrew Poulos

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web