1.1.0 • Published 3 years ago

cloud-archive-s3 v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

react-aws-s3

Open Source Module to Upload your Media and files into AWS S3 Bucket directly from Front-end React.

https://www.npmjs.com/package/react-aws-s3

S3Client AWS-S3

S3Client - A Javascript Library for AWS S3 File Upload

Using NPM

npm install --save react-aws-s3

Using Yarn

yarn add react-aws-s3

Examples Uploading An Image

Uploading to S3

import S3 from 'react-aws-s3';

const config = {
    bucketName: 'myBucket',
    dirName: 'media', /* optional */
    region: 'eu-west-1',
    accessKeyId: 'JAJHAFJFHJDFJSDHFSDHFJKDSF',
    secretAccessKey: 'jhsdf99845fd98qwed42ebdyeqwd-3r98f373f=qwrq3rfr3rf',
    s3Url: 'https:/your-custom-s3-url.com/', /* optional */,
    metaId: '14365123651274',
}

const ReactS3Client = new S3(config);
/*  Notice that if you don't provide a dirName, the file will be automatically uploaded to the root of your bucket */

/* This is optional */
const newFileName = 'test-file';

ReactS3Client
    .uploadFile(file, newFileName)
    .then(data => console.log(data))
    .catch(err => console.error(err))

  /**
   * {
   *   Response: {
   *     bucket: "myBucket",
   *     key: "image/test-image.jpg",
   *     location: "https://myBucket.s3.amazonaws.com/media/test-file.jpg",
   *     metaId: '14365123651274',
   *   }
   * }
   */
});

Deleting an existing file in your bucket

In this case the file that we want to delete is in the folder 'photos'

import S3 from 'react-aws-s3';


const config = {
    bucketName: 'myBucket',
    dirName: 'media', /* optional */
    region: 'eu-west-1',
    accessKeyId: 'JAJHAFJFHJDFJSDHFSDHFJKDSF',
    secretAccessKey: 'jhsdf99845fd98qwed42ebdyeqwd-3r98f373f=qwrq3rfr3rf',
    s3Url: 'https:/your-custom-s3-url.com/', /* optional */
}

const ReactS3Client = new S3(config);

const filename = 'hello-world.docx';

/* If the file that you want to delete it's in your bucket's root folder, don't provide any dirName in the config object */

//In this case the file that we want to delete is in the folder 'photos' that we referred in the config object as the dirName

ReactS3Client
    .deleteFile(filename)
    .then(response => console.log(response))
    .catch(err => console.error(err))

  /**
   * {
   *   Response: {
   *      ok: true,
          status: 204,
          message: 'File deleted',
          fileName: 'hello-world.docx'
   *   }
   * }
   */
});

Defaults your bucket to public-read : http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html

config

  • bucketName required - Your S3 bucket
  • dirName required - Your S3 folderName/dirName
  • region required - Your S3 bucket's region
  • accessKeyId required - Your S3 AccessKeyId
  • secretAccessKey required - Your S3 SecretAccessKey
  • s3Url optional - Your S3 URL

License

S3 Bucket Policy

Doc: http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html

MIT

acornacorn-dynamic-importalphanum-sortacorn-jsxany-baseansi-stylesaprobaansi-regexarr-diffargparseare-we-there-yetarr-flattenasyncroarray-uniqueassign-symbolsatobarr-unionbabel-plugin-transform-async-to-promisesautoprefixerbabylonbasebalanced-matchbig.jsblbracesbrace-expansionbrotli-sizebubleboolbasebrowserslistbuffer-alloc-unsafebuffer-allocbuffer-fillbuffer-fromcaller-pathcaller-callsitebuiltin-modulescaniuse-apicamelcasecaniuse-dbcaniuse-litecache-basecallsiteschownrchalkcloneclapcoaclass-utilscode-point-atcolor-namecolor-stringcolormincolor-convertcolorcommanderconcat-mapcomponent-emittercolorsconvert-source-mapconcat-with-sourcemapscosmiconfigcollection-visitcopy-descriptorcore-jscss-selectcrypto-jscss-modules-loader-corecss-select-base-adaptercss-color-namescss-treecss-declaration-sortercss-unit-convertercss-selector-tokenizercss-whatcssesccssnano-util-get-argumentscssnano-preset-defaultcssnano-util-get-matchcssnano-util-raw-cachecssnanodebugcssnano-util-same-parentcssodecamelizedecode-uri-componentdefine-propertydeep-extenddecompress-responsedefine-propertiescss-url-regexdefineddelegatesdetect-libcdom-serializerdomutilsdomelementtypeduplexerdot-propelectron-to-chromiumend-of-streamentitieserror-exemojis-listes6-promisifyescape-string-regexpes-abstractesutilsesprimaes-to-primitiveexpand-rangeestree-walkerexpand-templateextend-shallowfastparseextglobexpand-bracketsfiguresfilename-regexflattenflow-remove-typesfill-rangefragment-cachefilesizefor-infs-constantsfor-ownfs-extragaugeget-valuegeneric-namesgithub-from-packageglob-basefunction-bindglobalsglobrexglob-parentglobalyzergzip-sizegraceful-fshas-ansihas-flaghashas-unicodehas-symbolshas-valueshex-color-regexhas-valuehsla-regexhtml-comment-regexhsl-regexicss-replace-symbolsimport-cwdimport-fromiltorbinheritsiniimport-freshindexes-ofis-arrayishis-bufferis-accessor-descriptoris-callableis-date-objectis-data-descriptoris-color-stopis-descriptoris-absolute-urlis-directoryis-dotfileis-equal-shallowis-extendableis-fullwidth-code-pointis-globis-extglobis-numberis-moduleis-plain-objectis-plain-objis-objis-posix-bracketis-regexis-svgis-primitiveis-resolvableis-windowsis-symboljest-workerisarrayjs-base64isobjectjsescjs-yamljs-tokensjson-parse-better-errorsjsonfilekind-ofloader-utilslodash.camelcaselodashlodash.sumbylodash.memoizejson5lodash.foreachlodash.uniqmap-cachemath-expression-evaluatormagic-stringmap-visitmicrobundlemaxminmerge-streammath-randommdn-dataminimistmicromatchmimic-responsemixin-deepmkdirpminimatchmrimodule-details-from-pathnanomatchmsnode-releasesnapi-build-utilsnannode-abinormalize-rangenormalize-pathnormalize-urlnoop-loggernpmlognth-checknumber-is-nanobject-assignnum2fractionobject-keysobject-copyobject-visitobject.omitobject.getownpropertydescriptorsonceobject.pickobject.valuesp-queuepascalcaseparse-globos-homedirparse-jsonpath-parsepostcssposix-character-classespifypostcss-calcpostcss-colorminpostcss-convert-valuespostcss-discard-commentspostcss-discard-duplicatespostcss-discard-overriddenpostcss-discard-emptypostcss-load-optionspostcss-discard-unusedpostcss-filter-pluginspostcss-load-configpostcss-load-pluginspostcss-merge-identspostcss-merge-longhandpostcss-merge-rulespostcss-message-helperspostcss-minify-gradientspostcss-minify-selectorspostcss-minify-font-valuespostcss-minify-paramspostcss-modules-extract-importspostcss-modules-scopeconsole-control-stringspostcss-modulespostcss-modules-local-by-defaultpostcss-modules-valuespostcss-normalize-charsetpostcss-normalize-stringpostcss-normalize-display-valuespostcss-normalize-repeat-stylecore-util-ispostcss-normalize-positionspostcss-normalize-urlpostcss-normalize-timing-functionspostcss-normalize-whitespacepostcss-ordered-valuespostcss-normalize-unicodepostcss-reduce-identspostcss-reduce-initialpostcss-selector-parserpostcss-reduce-transformspostcss-svgopostcss-unique-selectorspostcss-zindexpostcss-value-parserprepend-httppreservepretty-bytesprebuild-installquery-stringqpumppromise.seriesrcprocess-nextick-argsreduce-css-calcreadable-streamrandomaticreduce-function-callregenerate-unicode-propertiesregenerateregex-notregex-cacheregenerator-runtimeregexpu-coreregjsgenrepeat-elementregjsparserrequire-from-stringreserved-wordsrepeat-stringretresolve-fromresolve-urlresolverolluprgba-regexremove-trailing-separatorrgb-regexrollup-plugin-babelrollup-plugin-bublerollup-plugin-es3rollup-plugin-bundle-sizerollup-plugin-jsonrollup-plugin-commonjsrollup-plugin-flowrollup-plugin-node-resolverollup-plugin-postcssrollup-plugin-typescript2rollup-plugin-preserve-shebangrollup-plugin-sizessaderollup-plugin-tersersaxsafe-regexsafe-bufferrollup-pluginutilsserialize-javascriptset-valueset-blockingsemvershort-uuidsimple-concatsignal-exitsimple-swizzlesnapdragon-nodesimple-getsnapdragonsort-keyssnapdragon-utilsource-mapsource-map-supportsource-map-resolvesourcemap-codecsplit-stringsource-map-urlsprintf-jsstrict-uri-encodestatic-extendstring-hashstablestring-widthstring_decoderstrip-json-commentsstrip-ansistylehacksstyle-injectsupports-colorsvgotimsorttar-streamtar-fstersertiny-globto-bufferto-fast-propertiesto-object-pathto-regexto-regex-rangetunnel-agentunicode-canonical-property-names-ecmascripttrim-righttslibtypescriptunicode-match-property-ecmascriptunicode-property-aliases-ecmascriptunion-valueuniqunicode-match-property-value-ecmascriptuniqsunquoteuniversalifyunset-valueurixutil-deprecateusevlqwhet.extendvendorsuuidwide-alignwhich-pm-runsutil.promisifyxtendwrappy
1.4.0

3 years ago

1.2.0

3 years ago

1.3.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago