Skip to content

Instantly share code, notes, and snippets.

View fulopdaniel's full-sized avatar

Daniel Fulop fulopdaniel

View GitHub Profile
export async function main(event, context, callback) {
parser(event).then(() => {
uploadFile(event.body.file)
.then(() => {
// Handle successful upload
})
.catch(() => {
// Handle upload errors
});
});
const uploadFile = (buffer) => new Promise((resolve, reject) => {
const bucketName = "YOUR-BUCKET-NAME";
const fileName = "YOUR-FILE-NAME.EXTENSION";
const data = {
Bucket: bucketName,
Key: fileName,
Body: buffer,
};
s3.putObject(data, (error) => {
if (!error) {
const getContentType = (event) => {
const contentType = event.headers['content-type']
if (!contentType) {
return event.headers['Content-Type'];
}
return contentType;
};
const parser = (event) => new Promise((resolve, reject) => {
const busboy = new Busboy({
handleFileUpload = (event) => {
this.setState({ file: event.target.files });
};
submitFile = (event) => {
event.preventDefault();
const formData = new FormData();
formData.append('file', this.state.file[0]);
axios
.post(
<form onSubmit={this.submitFile}>
<input
label="Upload file"
type="file"
onChange={this.handleFileUpload}
/>
<button type="submit">Upload</button>
</form>
{
"Version": "2012-10-17",
"Id": "Policy1532447175542",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:putObject",
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
}
"scripts": {
"build:translations": "react-intl-cra './src/**/*.js' -o ./build/messages/messages.json && babel scripts/translate.js | node && babel scripts/copyTranslationsToDB.js | node",
"fetch:translations": "babel scripts/fetchTranslationsFromDB.js | node",
}
import axios from 'axios';
import * as fs from 'fs';
import { sync as mkdirpSync } from 'mkdirp';
const supportedLanguages = ['en', 'hu'];
const API_URL = "YOUR API URL";
const LANG_DIR = './src/translations/';
axios.get(API_URL).then(() => {
"scripts": {
"build:translations": "react-intl-cra './src/**/*.js' -o ./build/messages/messages.json && babel scripts/translate.js | node && babel scripts/copyTranslationsToDB.js | node",
},
import axios from 'axios';
import messagesEn from './src/translations/temp/en.json'; // Import the extracted tokens
const messageKeys = [];
const API_URL = "YOUR API URL HERE";
Object.keys(messagesEn).forEach((message) => {
messageKeys.push(message); // I only send the tokens, not the default messages
});