Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 44 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,66 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const { Storage } = require('@google-cloud/storage');
'use strict';
const bucketName = "documents_database"
const storage = new Storage();

// [START gae_flex_quickstart]
const express = require('express');

const app = express();

async function downloadFile(fileName, destFileName) {
const options = {
destination: destFileName,
};

const bucket = storage.bucket(bucketName)
// Downloads the file
await bucket.file(fileName).download(options);

console.log(
`gs://${bucketName}/${fileName} downloaded to ${destFileName}.`
);
}


app.get('/', (req, res) => {
res.status(200).send('Hello, world!').end();
});

app.get('/download', async (req, res) => {
const { filename, destination } = req.query;

if (!filename) {
return res.status(400).send('Filename is required.');
}

const file = storage.bucket(bucketName).file(filename);

try {
const exists = await file.exists();
if (exists[0]) {
const destFileName = destination ? destination : `./${filename}`;
await downloadFile(filename, destFileName);
res.status(200).send(`File ${filename} downloaded successfully to ${destFileName}.`);
} else {
res.status(404).send(`File ${filename} not found.`);
}
} catch (err) {
console.error('Error:', err);
res.status(500).send('Internal Server Error');
}
});


// Start the server
const PORT = parseInt(process.env.PORT) || 8083;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
// [END gae_flex_quickstart]

module.exports = app;
3 changes: 3 additions & 0 deletions fisier_exemplu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exemplu text
123
a b c
12 changes: 12 additions & 0 deletions node_modules/.bin/fxparser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/fxparser.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/fxparser.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/uuid.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/uuid.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading