# UploadFS
**WARNING: This package will not receive any new features, only bug fixing when possible. The reason is that the Meteor package system is kind of obsolete now. I (the author of the package) plan to release a package on NPM that would work with other frameworks than Meteor, so it will be a full rewriting of UploadFS but with a completely different name. Thank you for your comprehension.**
UploadFS is a package for the Meteor framework that aims to make file uploading easy, fast and configurable.
Some important features are supported like the ability to **start, stop or even abort a transfer**, securing file access, transforming files on writing or reading...
If you want to support this package and feel graceful for all the work, please share this package with the community or feel free to send me pull requests if you want to contribute.
Also I'll be glad to receive donations, whatever you give it will be much appreciated.
If you find this lib useful and would like to contribute to it's development or just thank me (the author), donations are welcome.
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SS78MUMW8AH4N)
## Installation
To install the package, execute this command in the root of your project :
```
meteor add jalik:ufs
```
If later you want to remove the package :
```
meteor remove jalik:ufs
```
## Plugins
In this documentation, I am using the `UploadFS.store.Local` store which saves files on the filesystem.
But since the package is modular, you can install other stores or even create your own store.
* [UploadFS.store.Local](https://github.com/jalik/jalik-ufs-local)
* [UploadFS.store.GridFS](https://github.com/jalik/jalik-ufs-gridfs)
* [UploadFS.store.WABS](https://github.com/sebakerckhof/ufs-wabs)
* [UploadFS.store.S3](https://github.com/sebakerckhof/ufs-s3)
* [AutoForm-UFS](https://github.com/DesignmanIO/meteor-autoform-ufs)
## Testing
You can test the package by downloading and running [UFS-Example](https://github.com/jalik/ufs-example) which is simple demo of UploadFS.
## Mobile Testing
In order to test on mobile builds, `ROOT_URL` and `--mobile-server` must be set to your computer's local IP address and port:
```bash
export ROOT_URL=http://192.168.1.7:3000 && meteor run android-device --mobile-server=http://192.168.1.7:3000
```
## Configuration
You can access and modify settings via `UploadFS.config`.
```js
import {UploadFS} from 'meteor/jalik:ufs';
// Set default permissions for all stores (you can later overwrite the default permissions on each store)
UploadFS.config.defaultStorePermissions = new UploadFS.StorePermissions({
insert(userId, doc) {
return userId;
},
update(userId, doc) {
return userId === doc.userId;
},
remove(userId, doc) {
return userId === doc.userId;
}
});
// Use HTTPS in URLs
UploadFS.config.https = true;
// Activate simulation for slowing file reading
UploadFS.config.simulateReadDelay = 1000; // 1 sec
// Activate simulation for slowing file uploading
UploadFS.config.simulateUploadSpeed = 128000; // 128kb/s
// Activate simulation for slowing file writing
UploadFS.config.simulateWriteDelay = 2000; // 2 sec
// This path will be appended to the site URL, be sure to not put a "/" as first character
// for example, a PNG file with the _id 12345 in the "photos" store will be available via this URL :
// http://www.yourdomain.com/uploads/photos/12345.png
UploadFS.config.storesPath = 'uploads';
// Set the temporary directory where uploading files will be saved
// before sent to the store.
UploadFS.config.tmpDir = '/tmp/uploads';
// Set the temporary directory permissions.
UploadFS.config.tmpDirPermissions = '0700';
```
## Creating a Store (server)
**Since v0.6.7, you can share your store between client and server or define it on the server only.**
**Before v0.6.7, a store must be available on the client and the server.**
A store is the place where your files are saved, it could be your local hard drive or a distant cloud hosting solution.
Let say you have a `Photos` collection which is used to save the files info.
You need to create the store that will will contains the data of the `Photos` collection.
Note that the `name` of the store must be unique. In the following example we are using a local filesystem store.
Each store has its own options, so refer to the store documentation to see available options.
```js
import {Mongo} from 'meteor/mongo';
import {LocalStore} from 'meteor/jalik:ufs-local';
import {UploadFS} from 'meteor/jalik:ufs';
const Photos = new Mongo.Collection('photos');
const PhotoStore = new LocalStore({
collection: Photos,
name: 'photos',
path: '/uploads/photos'
});
```
## Filtering uploads (server)
### Filtering before uploading
You can filter uploads by assigning a `UploadFS.Filter` to a store.
The filter is tested before inserting a file in the collection.
If the file does not match the filter, it won't be inserted and will not be uploaded.
### Filtering after uploading
When the file is fully uploaded to the server, it's still in a temporary location.
At this moment you can validate the uploaded file before writing it to the store.
To do this, use `onValidate` option in the store options.
The following example shows a complete validation (before and after upload).
```js
import {Mongo} from 'meteor/mongo';
import {LocalStore} from 'meteor/jalik:ufs-local';
import {UploadFS} from 'meteor/jalik:ufs';
const Photos = new Mongo.Collection('photos');
const PhotoStore = new LocalStore({
collection: Photos,
name: 'photos',
path: '/uploads/photos',
// Apply a filter to restrict file upload
filter: new UploadFS.Filter({
minSize: 1,
maxSize: 1024 * 1000, // 1MB,
contentTypes: ['image/*'],
extensions: ['jpg', 'png']
}),
// Make sure that gallery pictures are indeed images
onValidate: function (file) {
// Here 'file' contains file metadata sent by the client, we need to get
// the disk path to the uploaded temp file to give it to gm.
const tempFilePath = UploadFS.getTempFilePath(file._id);
// Since the 'identify' function below is executed in a callback,
// we cannot directly throw an exception from it, because the exception would
// be catched by the server and not by ufs. We need to throw the exception
// from this onValidate function, so that ufs can catch the exception and
// trigger the cleanup process/report the error to the client.
// We do this by defining a future and waiting for it in onValidate, and having
// the future throw the exception instead of throwing it directly from
// the 'identify' function.
let future = new Future();
// identify will return an error if the content of the file is not an image.
// If it is an image, then details on the image file will be in data.
const identify = function (err, data) {
if (err) {
// Throw an exception to inform the client and trigger the cleanup process
future.throw(new Meteor.Error('not-an-image', 'The file is not an image'));
} else {
// We need to tell our future to return, or else it would stay stuck.
future.return();
}
};
gm(tempFilePath).identify(identify);
// Wait for 'identify' to complete, and either return or throw the exception
return future.wait();
}
});
```
If you need a more advanced filter, you can pass your own method using the `onCheck` option.
```js
import {Mongo} from 'meteor/mongo';
import {LocalStore} from 'meteor/jalik:ufs-local';
import {UploadFS} from 'meteor/jalik:ufs';
const Photos = new Mongo.Collection('photos');
const PhotoStore = new LocalStore({
collection: Photos,
name: 'photos',
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
rocketchat聊天服务器 v3.11.1.zip (2000个子文件)
people-sprites.css 261KB
activity-sprites.css 65KB
base_old.css 47KB
symbols-sprites.css 39KB
flags-sprites.css 36KB
objects-sprites.css 30KB
fontello.css 28KB
nature-sprites.css 25KB
travel-sprites.css 16KB
food-sprites.css 14KB
variables.css 12KB
theme_old.css 8KB
photoswipe.css 7KB
rtl.css 6KB
message-box.css 5KB
webdavFilePicker.css 5KB
style.css 5KB
popover.css 4KB
userInfo.css 4KB
messages.css 4KB
contextual-bar.css 4KB
emojiPicker.css 4KB
header.css 3KB
button.css 3KB
input.css 3KB
threads.css 3KB
forms.css 3KB
regional-sprites.css 3KB
base.css 3KB
popout.css 3KB
table.css 3KB
livechat.css 3KB
modal.css 2KB
sidebar.css 2KB
switch.css 2KB
apps.css 2KB
animations.css 2KB
main.css 2KB
login-button.css 2KB
select-avatar.css 1KB
styles.css 1KB
reaction.css 1KB
checkbox.css 1KB
reset.css 1KB
rooms-list.css 1KB
modifier-sprites.css 1KB
login-button.css 1KB
oauth2.css 1KB
style.css 1KB
select.css 1011B
github-enterprise-login-button.css 1006B
vrecord.css 1002B
popup-list.css 961B
login-button.css 951B
tags.css 937B
gitlab-login-button.css 904B
create-channel.css 896B
snippetPage.css 896B
tooltip.css 792B
loading.css 792B
readReceipts.css 772B
liveStreamTab.css 754B
sidebar-flex.css 736B
mentionLink.css 716B
emojione-sprites.css 703B
badge.css 689B
avatar.css 667B
tabs.css 664B
channelSettings.css 587B
editStatus.css 565B
autocomplete.css 498B
rocketchat.font.css 420B
main-content.css 374B
flex-nav.css 367B
messagepin.css 329B
chip.css 320B
messagestar.css 270B
style.css 257B
wordpress-login-button.css 213B
style.css 191B
video.css 169B
e2e.css 149B
typography.css 98B
说明.htm 4KB
createChannel.html 8KB
message.html 7KB
form.html 6KB
room.html 5KB
result.html 5KB
webdavFilePicker.html 5KB
CreateDiscussion.html 4KB
visitorInfo.html 4KB
visitorEdit.html 4KB
messageBox.html 4KB
livechatQueue.html 3KB
agentEdit.html 3KB
videoCall.html 3KB
liveStreamTab.html 3KB
closeRoom.html 3KB
modal.html 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
小小姑娘很大
- 粉丝: 4098
- 资源: 2348
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功