Open akshatshah opened 1 month ago
Could you please give me more info about your pains or requests? I'm always open to any such PR but I want to know more about your situation.
Essentially let's say you have a pdf link that needs a auth token to enable access for the client device. I wasn't able to find a way to pass headers to the http request.
Current Setup:
Get the file from cache (download if not available already):
Future<Either<ApiFailure, String>> getFilePath(String url) async {
try {
final credentials = await _authController.getUserCredentials();
final headers = credentials.authHeader;
final file = await _cacheManager.getSingleFile(
url,
headers: headers,
);
return right(file.path);
} catch (e) {
return left(ApiFailure.platform(LocaleKeys.standardErrorMessage.tr()));
}
}
Pass the path to the cached file in the PdfViewer
return PdfViewer.file(
path,
Ideal Setup would be to pass the headers to the widget itself (or having a custom client option that can make authenticated requests). Here the headers would have a bearer token that allows the client to access the file:
PdfViewer.uri(
uri,
headers: {
'Authorization': 'Bearer <token>'
....
Maybe I am missing something and this feature already exists. I would love some guidance if that's the case.
Could you please check 5717726e31dbfcaee7bba0d332c260ab62d7a095?
It introduces headers
to PdfDocument.openUri function.
1.0.57 contains the fix above.
Hey, sorry for the delayed response. I just tried to test but there is no way to pass the headers to the PdfDocument.openUri function from the widget. I went through the code and adding links to places where headers parameter would be needed below so that we can pass it from the widget. Thank you for all your help so far!
We have been trying to figure out a way to use the PdfViewer.uri widget with a link that requires authenticated headers. The current setup we have uses a separate cache mechanism to download the file and then pass it on to the PdfViewer widget. Being able to pass the headers directly to the widget would be optimal in terms of caching and performance. Any insight on this would be appreciated. I would also be willing to work on a PR for this if you're open to it!