import { ref } from 'vue';
import { Storage } from '@google-cloud/storage';
const storageInstance = ref<Storage | null>(null);
export function useGoogleStorage() {
if (!import.meta.server) {
throw new Error('useGoogleStorage can only be used on the server side.');
}
if (!storageInstance.value) {
storageInstance.value = new Storage();
}
const uploadFile = async (bucketName: string, filePath: string, destination: string, contentType: string) => {
if (!storageInstance.value) return;
const bucket = storageInstance.value.bucket(bucketName);
console.log('Uploading file to Google Cloud Storage:', destination);
console.log('File path:', filePath);
console.log('Content type:', contentType);
await bucket.upload(filePath, {
destination,
metadata: {
contentType
}
});
};
}
import { ref } from 'vue';
import { Storage } from '@google-cloud/storage';
const storageInstance = ref<Storage | null>(null);
export function useGoogleStorage() {
if (!import.meta.server) {
throw new Error('useGoogleStorage can only be used on the server side.');
}
if (!storageInstance.value) {
storageInstance.value = new Storage();
}
const uploadFile = async (bucketName: string, filePath: string, destination: string, contentType: string) => {
if (!storageInstance.value) return;
const bucket = storageInstance.value.bucket(bucketName);
console.log('Uploading file to Google Cloud Storage:', destination);
console.log('File path:', filePath);
console.log('Content type:', contentType);
await bucket.upload(filePath, {
destination,
metadata: {
contentType
}
});
};
}