Comments (3)
I found out how to solve this problem, two fields must be added, one in Policy and the other in Body, looking like this:
final Dio _client = Dio();
_client.interceptors.add(LogInterceptor());
final int length = await image.length();
final String filename = '${DateTime.now().millisecondsSinceEpoch}.jpg';
final String key = path + filename;
final Policy policy = Policy.fromS3PreSignedPost(
key,
bucketId,
500,
accessKey,
length,
sessionToken,
region: region,
);
final List<int> signKey =
SigV4.calculateSigningKey(secretKey, policy.datetime, region, service);
final String signature = SigV4.calculateSignature(signKey, policy.encode());
final FormData formData = FormData.fromMap({
'key': policy.key,
'acl': 'public-read',
'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
'X-Amz-Credential': policy.credential,
'X-Amz-Date': policy.datetime,
'Policy': policy.encode(),
'X-Amz-Signature': signature,
'x-amz-security-token': sessionToken,
'Content-Type': 'image/jpeg',
'file': await MultipartFile.fromFile(
image.path,
filename: filename,
)
});
Response response = await _client.post(post, data: formData);
_client.close();
String linkImage = response.headers.map['location'].first;
class Policy {
String expiration;
String region;
String bucket;
String key;
String credential;
String datetime;
String sessionToken;
int maxFileSize;
Policy(this.key, this.bucket, this.datetime, this.expiration, this.credential,
this.maxFileSize, this.sessionToken,
{this.region = AWS_REGION_FTALK});
factory Policy.fromS3PreSignedPost(
String key,
String bucket,
int expiryMinutes,
String accessKeyId,
int maxFileSize,
String sessionToken, {
String region,
}) {
final datetime = SigV4.generateDatetime();
final expiration = (DateTime.now())
.add(Duration(minutes: expiryMinutes))
.toUtc()
.toString()
.split(' ')
.join('T');
final cred =
'$accessKeyId/${SigV4.buildCredentialScope(datetime, region, 's3')}';
final policy = Policy(
key, bucket, datetime, expiration, cred, maxFileSize, sessionToken,
region: region);
return policy;
}
String encode() {
final bytes = utf8.encode(toString());
return base64.encode(bytes);
}
@override
String toString() {
return '''
{ "expiration": "${this.expiration}",
"conditions": [
{"bucket": "${this.bucket}"},
["starts-with", "\$key", "${this.key}"],
["starts-with", "\$Content-Type", "image/"],
{"acl": "public-read"},
["content-length-range", 1, ${this.maxFileSize}],
{"x-amz-credential": "${this.credential}"},
{"x-amz-algorithm": "AWS4-HMAC-SHA256"},
{"x-amz-date": "${this.datetime}" },
{"x-amz-security-token": "${this.sessionToken}" }
]
}
''';
}
}
from amazon-cognito-identity-dart-2.
Pls take a look at this working code, it seems like this is the same as you trying to implement
https://github.com/conghua2411/FlutterDemoEverything/blob/e07cd5e1c9f751395a050a9a37ed09e821ee607b/lib/aws_cognito_dev_upload_s3/aws_cognito_dev_upload_s3.dart
from amazon-cognito-identity-dart-2.
Por favor, dê uma olhada neste código funcional, parece que é o mesmo que você está tentando implementar
https://github.com/conghua2411/FlutterDemoEverything/blob/e07cd5e1c9f751395a050a9a37ed09e821ee607b/lib/aws_cognito_dev_upload_s3/aws_cognito_dev_upload_s3/aws_cognito_dev_upload_s3/aws_cognito
Unfortunately it had the same effect, when uploading the image and opening it on AWS it looks like this:
I need metadata to look like this:
I have the need to change the metadata, because when opening the link, the image is downloaded automatically, and instead I need the image to be opened when clicking on the link, due to my web application that also includes the images. If you have any suggestions on what to do, I will be very grateful!
from amazon-cognito-identity-dart-2.
Related Issues (20)
- SMS-MFA fails when pool allows users to sign in using email HOT 3
- SAML user pool IdP authentication flow HOT 2
- SSO w/ Flutter AWS Cognito HOT 2
- zip file broken HOT 2
- use case 19 HOT 2
- Unauthorized/Anonymus user token HOT 2
- Forgot Password HOT 2
- Melos version bump? HOT 5
- [ASK] Is it possible to getSession with only `refreshToken` value ? HOT 2
- Use case 19 HOT 3
- CognitoUserDeviceConfirmationNecessaryException is not being thrown HOT 3
- Enabling TOTP for MFA HOT 5
- how to solve custom challenge? HOT 3
- Federated Login... Refresh Access Token HOT 2
- AuthenticationDetails.validationData not transmitted HOT 5
- VerifyDevice request fails if username used in sendMFA() is email or phone number HOT 2
- MFA_SETUP challenge when user pool has "required MFA" HOT 3
- sendMFACode method requires SECRET_HASH HOT 2
- How to verify Password Only without session? HOT 2
- "Missing required parameter Session" while MFA is required HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amazon-cognito-identity-dart-2.