how can I use aws-sdk in typescript
I used typescript ( tsx ) for react . In upload image task , I used aws-sdk to upload to server s3 . I also installed aws-sdk by npm and typings .
UploadFile.tsx
import * as AWS from 'aws-sdk';
//constant
import DefaultValue from '../../Constants/DefaultValue';
AWS.config.update({
region: DefaultValue.REGION,
credentials: new AWS.Credentials(DefaultValue.ACCESS_KEY_ID, DefaultValue.SECRET_KEY)
});
class UploadFile extends React.Component<any,any> {
s3: any;
constructor() {
super();
this.s3 = new AWS.S3({apiVersion: '2016-11-07'});
}
}
Chrome console error : 'AWS is undefined' . how can i import AWS ? thanks for help .
@ducduongtmb Are you using a tool like webpack or browserify to bundle your code, or are you including the SDK by adding a script tag to your page?
You should be able to use the following when using a tool like webpack or browserify (or in node.js):
import AWS = require('aws-sdk');
Otherwise if you're including the SDK with a script tag, AWS should be available as a global variable. For type information, if you're using typescript 2.x, you can include this comment at the top of your JS file:
/// <reference types="aws-sdk" />
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.