Search code examples
node.jsfluttersocket.ioflutter-web

Flutter File Picker Cross:- Failed to execute 'setItem' on 'Storage': Setting the value of 'file_picker_cross_file_system' exceeded the quota


I am building a flutter web application which picks multiple files and uploads them to a server using sockets. For Flutter here are the packages i am using

Here is my pubspec.yaml file

dependencies:
  flutter:
    sdk: flutter
    cupertino_icons: ^1.0.1
    file_picker_cross: ^4.3.2
    http: ^0.13.1
    socket_io_client: ^2.0.0-beta.2

Here is the function to pick files and initialize the sockets

    void _selectFile(context) {
      FilePickerCross.importMultipleFromStorage().then((filePicker) {
      filePicker.forEach((element) {
      setFilePicker(element);
       });
      });
   }
  setFilePicker(FilePickerCross filePicker) => setState(() {
    filePickerCross = filePicker;
    filePickerCross.saveToPath(path: filePickerCross.fileName);
    // FilePickerCross.quota().then((value) {
    //   setState(() => quota = value);
    // });
    lastFiles.add(filePickerCross.fileName);

    try {
      _fileString = filePickerCross.toString();
    } catch (e) {
      _fileString = filePickerCross.toBase64();
    }
  });

  _socketClient() async {
print("auto true");
var socket = io.io('http://localhost:3010', <String, dynamic>{
  'transports': ['websocket'],
  'autoConnect': true,
});

socket.on('connect', (_) {
  print('connect');
  socket.emit(
    'filedetails',
    {
      'data': _fileString,
      'path': filePickerCross.path,
      'len': filePickerCross.length,
    },
  );
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) {
  setState(() {
    msgRx = 'From server: $_';
  });
});
socket.on('connect_error', (_) => print('socket connect_error: $_'));
socket.on('error', (_) => print('socket error: $_'));

}

I have a simple NodeJS server using socket where i wait for the connection from the client. When i connect to the server, i get the following error

DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'file_picker_cross_file_system' exceeded the quota.
at Storage.[_setItem] (http://localhost:52078/dart_sdk.js:97142:27)
at Storage.[dartx._set] (http://localhost:52078/dart_sdk.js:97072:25)
at Object.saveLocalFileSystem (http://localhost:52078/packages/file_picker_cross/src/file_picker_web.dart.lib.js:296:36)
at saveInternalBytes (http://localhost:52078/packages/file_picker_cross/src/file_picker_web.dart.lib.js:201:23)
at saveInternalBytes.next (<anonymous>)
at runBody (http://localhost:52078/dart_sdk.js:39051:34)
at Object._async [as async] (http://localhost:52078/dart_sdk.js:39082:7)
at Object.saveInternalBytes (http://localhost:52078/packages/file_picker_cross/src/file_picker_web.dart.lib.js:198:18)
at file_picker_cross.FilePickerCross.new.saveToPath (http://localhost:52078/packages/file_picker_cross/src/file_picker_web.dart.lib.js:388:30)
at http://localhost:52078/packages/photo_measure/poc/socket_io_img_video.dart.lib.js:875:30
at socket_io_img_video._SocketIoClientPocFileUploadState.new.setState (http://localhost:52078/packages/flutter/src/widgets/widget_span.dart.lib.js:16616:22)      
at socket_io_img_video._SocketIoClientPocFileUploadState.new.setFilePicker
(http://localhost:52078/packages/photo_measure/poc/socket_io_img_video.dart.lib.js:873:19)
at http://localhost:52078/packages/photo_measure/poc/socket_io_img_video.dart.lib.js:865:16
at Array.[dartx.forEach] (http://localhost:52078/dart_sdk.js:15665:11)
at http://localhost:52078/packages/photo_measure/poc/socket_io_img_video.dart.lib.js:864:29
at _RootZone.runUnary (http://localhost:52078/dart_sdk.js:38888:58)
at _FutureListener.then.handleValue (http://localhost:52078/dart_sdk.js:33874:29)
at handleValueCallback (http://localhost:52078/dart_sdk.js:34434:49)
at Function._propagateToListeners (http://localhost:52078/dart_sdk.js:34472:17)
at _Future.new.[_completeWithValue] (http://localhost:52078/dart_sdk.js:34314:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:52078/dart_sdk.js:34337:35)
at Object._microtaskLoop (http://localhost:52078/dart_sdk.js:39175:13)
at _startMicrotaskLoop (http://localhost:52078/dart_sdk.js:39181:13)
at http://localhost:52078/dart_sdk.js:34688:9

Solution

  • I was able to fix the issue. I called the dispose function whenever the sockets were full. When dispose is called, the sockets refreshes.

    Thus rectifying the error