developer.chrome.com icon indicating copy to clipboard operation
developer.chrome.com copied to clipboard

in chrome private mode, 'NotReadableError' error when using reader.readAsArrayBuffer(file.slice(0, 1024)), file is geted from indexedDB.

Open meiqi502 opened this issue 4 years ago • 15 comments

⚠️ This is for issues with the https://developer.chrome.com site, not Chromium itself. If you want to file a bug with Chromium (the open-source project behind Google Chrome and other browsers), please use https://crbug.com.

Describe the bug in chrome private mode, after i store a video in indexedDB, then i get the video file from indexedDB and read it using FileReader Api, it has a 'NotReadableError' error when i use reader.readAsArrayBuffer(file.slice(0, 1024)) . it works well when not in Chrome Incognito Mode.

To Reproduce Steps to reproduce the behavior:

  1. store a file in indexedDB
  2. get the file from indexedDB
  3. new FileReader() and read file chunk by using file.slice(0, chunkSize)
  4. open page in chrome private mode
  5. See error

Expected behavior no 'NotReadableError' happen

Screenshots image

Desktop (please complete the following information):

  • OS: os x
  • Browser: chrome
  • Version: 100.0.4896.75

Additional context Add any other context about the problem here.

meiqi502 avatar Apr 10 '22 13:04 meiqi502

What is meant by private mode?

What is the result of the following?

try {
  console.log(await new Response(file.slice(0, 1024)).arrayBuffer());
} catch (e) {
  console.error(e);
}

Can you post the relevant code here?

guest271314 avatar Apr 10 '22 16:04 guest271314

너희들은 미국 연방국법원에 변호사를 보내 고소할꺼야. 자료가 넘 많다

2022년 4월 11일 (월) 01:38, guest271314 @.***>님이 작성:

What is meant by private mode?

What is the result of the following?

try { console.log(await new Response(file.slice(0, 1024)).arrayBuffer()); } catch (e) { console.error(e); }

Can you post the relevant code here?

— Reply to this email directly, view it on GitHub https://github.com/GoogleChrome/developer.chrome.com/issues/2563#issuecomment-1094309636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYR2FSZD2LFZGQISLFALMZTVEL7Y7ANCNFSM5TAZ3ADQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Im2451soon avatar Apr 10 '22 17:04 Im2451soon

@Im2451soon I am only interested in the code.

guest271314 avatar Apr 10 '22 18:04 guest271314

private mode meant Chrome Incognito Mode,

try { console.log(await new Response(file.slice(0, 1024)).arrayBuffer()); } catch (e) { console.error(e); } result is: image

meiqi502 avatar Apr 11 '22 02:04 meiqi502

What is meant by private mode?

What is the result of the following?

try {
  console.log(await new Response(file.slice(0, 1024)).arrayBuffer());
} catch (e) {
  console.error(e);
}

Can you post the relevant code here?

i write a demo, here is code, copy and save as demo.html and run http-server, then open page in chrome Incognito mode. thank you!

// demo.html
<!DOCTYPE html>
<html>
<head>
	<title>demo</title>
</head>
<body>
	<h2>step 1: select a file and store in indexedDB</h2>
	<input type="file" id="input" />

	<h2>step2: get the file from indexedDB and slice file</h2>
	<button id="button">get file and slice</button>
	<section>
	  <div>name:</div>
	  <div id="name">--</div>
	  <div>size:</div>
	  <div id="size">--</div>
	</section>

</body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dexie/3.2.1/dexie.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.3.2/uuid.min.js"></script>
<script type="text/javascript">
	class VideoDB extends Dexie {
  constructor() {
    super('videodb');
    this.version(1).stores({
      video: 'url' // Primary key and indexed props
    });
  }
}

const db = new VideoDB();
let lastUrl = '';

document.getElementById('input').addEventListener('change', (e) => {
  const [file] = e.target.files;
  const name = file.name || Date.now();
  lastUrl = uuid.v5(name, uuid.v5.URL);
  db.video.add({
    url: lastUrl,
    file,
  });
});

document.getElementById('button').addEventListener('click', async (e) => {
  const raw = await db.video.get(lastUrl);
  console.log(raw);
  const { file, url } = raw;
  document.getElementById('name').innerHTML = file?.name;
  document.getElementById('size').innerHTML = file?.size;
  try {
    const ab = await new Response(file.slice(0, 1024)).arrayBuffer();
    console.log(ab);
  } catch(e) {
    console.error(e.message);
  }
});

</script>
</html>

meiqi502 avatar Apr 11 '22 03:04 meiqi502

If you do something like this you can access the data

const buffer = await file.arrayBuffer();
  console.log(buffer);
  document.getElementById('name').innerHTML = file?.name;
  document.getElementById('size').innerHTML = file?.size;
  try {
    const ab = buffer.slice(0, 1024);
    console.log(ab);

guest271314 avatar Apr 11 '22 06:04 guest271314

@meiqi502 Substitute using Blob.arrayBuffer() for FileReader and Response() plnkr https://plnkr.co/edit/PqZH1wToPuzPGgEL?preview

guest271314 avatar Apr 11 '22 06:04 guest271314

@meiqi502 Substitute using Blob.arrayBuffer() for FileReader and Response() plnkr https://plnkr.co/edit/PqZH1wToPuzPGgEL?preview

thank you for your apply! and i have saw your code, but there is two question: 1、when the file is huge such as > 3Gb, file.arrayBuffer() trigger error: The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired 2、the point i want to do slice before arraybuffer is memory used. read whole file need to use huge memory. image

can i slice the file first and then read arraybuffer? any replay will be appreciated~

meiqi502 avatar Apr 11 '22 07:04 meiqi502

Do you have a 3GB file that is exposed on the Web I can test with?

Why is Incognito mode necessary?

guest271314 avatar Apr 11 '22 13:04 guest271314

Do you have a 3GB file that is exposed on the Web I can test with?

Why is Incognito mode necessary?

sorry i don‘t i met this error and really want to know why, is it normal? or is it a bug? thank you for your apply~

meiqi502 avatar Apr 12 '22 02:04 meiqi502

Have you tried navigating to Settings -> Privacy and Security -> Cookies and other site data -> Sites that can always use cookies -> ?

Blobs are stored various ways https://stackoverflow.com/a/56419176. ArrayBuffer are evidently stored differently on Chromium/Chrome. Using ArrayBuffer might be the solution for Incognito mode with your use case.

guest271314 avatar Apr 12 '22 03:04 guest271314

is it normal? or is it a bug?

Difficult to make the determination if that is working as intended in Incognito mode. The workaround is using ArrayBuffer via Blob.arrayBuffer().

guest271314 avatar Apr 12 '22 03:04 guest271314

Have you tried navigating to Settings -> Privacy and Security -> Cookies and other site data -> Sites that can always use cookies -> ?

Blobs are stored various ways https://stackoverflow.com/a/56419176. ArrayBuffer are evidently stored differently on Chromium/Chrome. Using ArrayBuffer might be the solution for Incognito mode with your use case.

i have tried setting just now,and it seems nothing change

meiqi502 avatar Apr 12 '22 03:04 meiqi502

is it normal? or is it a bug?

Difficult to make the determination if that is working as intended in Incognito mode. The workaround is using ArrayBuffer via Blob.arrayBuffer().

ok, thanks a lot

meiqi502 avatar Apr 12 '22 03:04 meiqi502

Ran into this issue as well. A similar Chromium issue was reported. A workaround (suggested in that issue) of cloning the file before further use worked for me:

const buffer = await file.arrayBuffer();
const clone = new File([buffer], file.name, { type: file.type });

kdugue-uber avatar Mar 10 '23 21:03 kdugue-uber