-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathParseFile.d.ts
189 lines (189 loc) · 6.4 KB
/
ParseFile.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import type { FullOptions } from './RESTController';
interface Base64 {
base64: string;
}
interface Uri {
uri: string;
}
type FileData = number[] | Base64 | Blob | Uri;
export type FileSaveOptions = FullOptions & {
metadata?: Record<string, any>;
tags?: Record<string, any>;
};
export type FileSource = {
format: 'file';
file: Blob;
type: string | undefined;
} | {
format: 'base64';
base64: string;
type: string | undefined;
} | {
format: 'uri';
uri: string;
type: string | undefined;
};
export declare function b64Digit(number: number): string;
/**
* A Parse.File is a local representation of a file that is saved to the Parse
* cloud.
*
* @alias Parse.File
*/
declare class ParseFile {
_name: string;
_url?: string;
_source: FileSource;
_previousSave?: Promise<ParseFile>;
_data?: string;
_requestTask?: any;
_metadata?: Record<string, any>;
_tags?: Record<string, any>;
/**
* @param name {String} The file's name. This will be prefixed by a unique
* value once the file has finished saving. The file name must begin with
* an alphanumeric character, and consist of alphanumeric characters,
* periods, spaces, underscores, or dashes.
* @param data {Array} The data for the file, as either:
* 1. an Array of byte value Numbers or Uint8Array.
* 2. an Object like { base64: "..." } with a base64-encoded String.
* 3. an Object like { uri: "..." } with a uri String.
* 4. a File object selected with a file upload control. (3) only works
* in Firefox 3.6+, Safari 6.0.2+, Chrome 7+, and IE 10+.
* For example:
* <pre>
* var fileUploadControl = $("#profilePhotoFileUpload")[0];
* if (fileUploadControl.files.length > 0) {
* var file = fileUploadControl.files[0];
* var name = "photo.jpg";
* var parseFile = new Parse.File(name, file);
* parseFile.save().then(function() {
* // The file has been saved to Parse.
* }, function(error) {
* // The file either could not be read, or could not be saved to Parse.
* });
* }</pre>
* @param type {String} Optional Content-Type header to use for the file. If
* this is omitted, the content type will be inferred from the name's
* extension.
* @param metadata {object} Optional key value pairs to be stored with file object
* @param tags {object} Optional key value pairs to be stored with file object
*/
constructor(name: string, data?: FileData, type?: string, metadata?: object, tags?: object);
/**
* Return the data for the file, downloading it if not already present.
* Data is present if initialized with Byte Array, Base64 or Saved with Uri.
* Data is cleared if saved with File object selected with a file upload control
*
* @returns {Promise} Promise that is resolve with base64 data
*/
getData(): Promise<string>;
/**
* Gets the name of the file. Before save is called, this is the filename
* given by the user. After save is called, that name gets prefixed with a
* unique identifier.
*
* @returns {string}
*/
name(): string;
/**
* Gets the url of the file. It is only available after you save the file or
* after you get the file from a Parse.Object.
*
* @param {object} options An object to specify url options
* @param {boolean} [options.forceSecure] force the url to be secure
* @returns {string | undefined}
*/
url(options?: {
forceSecure?: boolean;
}): string | undefined;
/**
* Gets the metadata of the file.
*
* @returns {object}
*/
metadata(): Record<string, any>;
/**
* Gets the tags of the file.
*
* @returns {object}
*/
tags(): Record<string, any>;
/**
* Saves the file to the Parse cloud.
*
* @param {object} options
* Valid options are:<ul>
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
* be used for this request.
* <li>sessionToken: A valid session token, used for making a request on
* behalf of a specific user.
* <li>progress: In Browser only, callback for upload progress. For example:
* <pre>
* let parseFile = new Parse.File(name, file);
* parseFile.save({
* progress: (progressValue, loaded, total, { type }) => {
* if (type === "upload" && progressValue !== null) {
* // Update the UI using progressValue
* }
* }
* });
* </pre>
* </ul>
* @returns {Promise | undefined} Promise that is resolved when the save finishes.
*/
save(options?: FileSaveOptions & {
requestTask?: any;
}): Promise<ParseFile> | undefined;
/**
* Aborts the request if it has already been sent.
*/
cancel(): void;
/**
* Deletes the file from the Parse cloud.
* In Cloud Code and Node only with Master Key.
*
* @param {object} options
* Valid options are:<ul>
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
* be used for this request.
* <pre>
* @returns {Promise} Promise that is resolved when the delete finishes.
*/
destroy(options?: FullOptions): Promise<this>;
toJSON(): {
__type: 'File';
name?: string;
url?: string;
};
equals(other: any): boolean;
/**
* Sets metadata to be saved with file object. Overwrites existing metadata
*
* @param {object} metadata Key value pairs to be stored with file object
*/
setMetadata(metadata: Record<string, any>): void;
/**
* Sets metadata to be saved with file object. Adds to existing metadata.
*
* @param {string} key key to store the metadata
* @param {*} value metadata
*/
addMetadata(key: string, value: any): void;
/**
* Sets tags to be saved with file object. Overwrites existing tags
*
* @param {object} tags Key value pairs to be stored with file object
*/
setTags(tags: Record<string, any>): void;
/**
* Sets tags to be saved with file object. Adds to existing tags.
*
* @param {string} key key to store tags
* @param {*} value tag
*/
addTag(key: string, value: string): void;
static fromJSON(obj: any): ParseFile;
static encodeBase64(bytes: number[] | Uint8Array): string;
}
export default ParseFile;