Trying to list the files stored in blob storage container. Generated SAS url and used the following program.but getting error
Error - Failed to fetch data: 403
import 'dart:convert';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
void main() async {
final String folderURL = 'https://myblobaccount.blob.core.windows.net/azure-webjobs-hosts?sp=r&st=2024-03-22T07:21:47Z&se=2024-03-22T15:21:47Z&sv=2022-11-02&sr=c&sig=Eg%2B04lD3EWLo2wGocU9mqNjKwqKmo04zSCH0Dbsjqlg%3D';//$storageBlobEndpoint/$containerName?$sasToken';
// Make a request to list the blobs within the folder
final response = await http.get(Uri.parse(folderURL));
if (response.statusCode == 200) {
final List<dynamic> blobs = json.decode(response.body);
print("Files in the folder:");
for (var blob in blobs) {
print(blob['name']);
}
} else {
print('Failed to fetch data: ${response.statusCode}');
}
}
what could be the issue?
Error - Failed to fetch data: 403
Even when I tried with the same Container URL, I got the same error.
Error:
The above error occurred due to using an incorrect URL, which you passed to make the request.
To list the blobs, you need to use the URL below.
Request:
https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list&<Your sas token>
Output:
Reference: