babakcode / o3d

The Flutter 3D objects easy controller ( glb format )
https://pub.dev/packages/o3d
BSD 3-Clause "New" or "Revised" License
32 stars 12 forks source link

Provide ability to pass http headers in network call #5

Open ueft-kyriv opened 7 months ago

ueft-kyriv commented 7 months ago

Hi Babak,

I was wondering if you plan on including the ability to add http headers within the O3D.network method? Because the nature of our 3D models we require users to be authenticated before we return the GLB model. In our other API calls we require the Authorization header to be present with a valid token.

Do you plan on adding the ability for headers to be passed to the network call?

babakcode commented 7 months ago

Hello @ueft-kyriv, I apologize for my delayed reply—I've been quite busy. Unfortunately, the feature you're inquiring about isn't currently active in the main JavaScript script of the model-viewer. However, there are alternative ways to bring this concept to life. One approach is to use the Dio library to download the GLB model from the server, including the desired header data in the request. You can then load these models from the app's cache directory as Dart IO Files. Alternatively, for the web platform, you can obtain them as Blob file data. If you're interested, I can help you implement this idea. At the moment, though, I'm unable to add this feature immediately.

itissalma commented 2 months ago

How would you go about using the Dio to download the model? I am trying to display a glb that I get from an api call.

babakcode commented 2 months ago

Hi @itissalma. it's easy. Write a get request then put the following code for your request's option property.

responseType: ResponseType.bytes,

then you can store received bytes of data in the desired directory.


      File file = File(savePath);
      var raf = file.openSync(mode: FileMode.write);
      // response.data is List<int> type
      raf.writeFromSync(response.data);
      await raf.close();

However, I believe you did, but you couldn't download the file because you didn't set cors for the server side.