1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[5903],{3905:(e,t,i)=>{i.d(t,{Zo:()=>c,kt:()=>h});var n=i(7294);function r(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function l(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function a(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?l(Object(i),!0).forEach((function(t){r(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):l(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function s(e,t){if(null==e)return{};var i,n,r=function(e,t){if(null==e)return{};var i,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)i=l[n],t.indexOf(i)>=0||(r[i]=e[i]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)i=l[n],t.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(e,i)&&(r[i]=e[i])}return r}var o=n.createContext({}),d=function(e){var t=n.useContext(o),i=t;return e&&(i="function"==typeof e?e(t):a(a({},t),e)),i},c=function(e){var t=d(e.components);return n.createElement(o.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},f=n.forwardRef((function(e,t){var i=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),p=d(i),f=r,h=p["".concat(o,".").concat(f)]||p[f]||u[f]||l;return i?n.createElement(h,a(a({ref:t},c),{},{components:i})):n.createElement(h,a({ref:t},c))}));function h(e,t){var i=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=i.length,a=new Array(l);a[0]=f;var s={};for(var o in t)hasOwnProperty.call(t,o)&&(s[o]=t[o]);s.originalType=e,s[p]="string"==typeof e?e:r,a[1]=s;for(var d=2;d<l;d++)a[d]=i[d];return n.createElement.apply(null,a)}return n.createElement.apply(null,i)}f.displayName="MDXCreateElement"},7198:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>s,metadata:()=>d,toc:()=>p});var n=i(7462),r=i(3366),l=(i(7294),i(3905)),a=["components"],s={title:"Files Service"},o=void 0,d={unversionedId:"sdk/hive/swift/guides/files-service",id:"sdk/hive/swift/guides/files-service",title:"Files Service",description:"Hive SDK uploads files to the corresponding Vault through the FilesService class. File is one of the data types supported by Hive SDK. The FileService class is one of the derived sub-services in Vault Service, which is used to support the operation of file types, such as uploading, downloading, and deleting. Once the data is uploaded to Hive Node, its file block data is hosted and saved in the corresponding IPFS Node, while its metadata information is hosted in the Vault internal database.",source:"@site/../docs/7.sdk/hive/swift/guides/files-service.md",sourceDirName:"7.sdk/hive/swift/guides",slug:"/sdk/hive/swift/guides/files-service",permalink:"/sdk/hive/swift/guides/files-service",draft:!1,editUrl:"https://github.com/elastos/Elastos.Wiki/edit/master/website/../docs/7.sdk/hive/swift/guides/files-service.md",tags:[],version:"current",lastUpdatedBy:"racollette",lastUpdatedAt:1678815391,formattedLastUpdatedAt:"Mar 14, 2023",frontMatter:{title:"Files Service"},sidebar:"sdkSidebar",previous:{title:"Backup Subscription",permalink:"/sdk/hive/swift/guides/backup-subscription"},next:{title:"Database Service",permalink:"/sdk/hive/swift/guides/database-service"}},c={},p=[{value:"Upload File",id:"upload-file",level:2},{value:"Upload File Data by Writing File Stream Interface Writer",id:"upload-file-data-by-writing-file-stream-interface-writer",level:3},{value:"Download File",id:"download-file",level:2},{value:"List Files",id:"list-files",level:2},{value:"Stat",id:"stat",level:2},{value:"Move",id:"move",level:2},{value:"Delete",id:"delete",level:2}],u={toc:p},f="wrapper";function h(e){var t=e.components,i=(0,r.Z)(e,a);return(0,l.kt)(f,(0,n.Z)({},u,i,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("p",null,"Hive SDK uploads files to the corresponding Vault through the FilesService class. File is one of the data types supported by Hive SDK. The FileService class is one of the derived sub-services in Vault Service, which is used to support the operation of file types, such as uploading, downloading, and deleting. Once the data is uploaded to Hive Node, its f
1ile block data is hosted and saved in the corresponding IPFS Node, while its metadata information is hosted in the Vault internal database."),(0,l.kt)("h2",{id:"upload-file"},"Upload File"),(0,l.kt)("h3",{id:"upload-file-data-by-writing-file-stream-interface-writer"},"Upload File Data by Writing File Stream Interface Writer"),(0,l.kt)("p",null,"When uploading a file, you need to get the FilesService interface instance from the Vault instance, and then set the target path (REMOTE_FILE_PATH) to get the remote write file stream interface instance Writer. At the same time, you'll need to write the file content into the file stream. The process of writing file data is that of uploading file data."),(0,l.kt)("p",null,"The whole process of uploading files using FileService instance is connected in series through the CompletableFuture mode, and a CompletableFuture object is returned that indicates whether the file upload succeeds or fails and an exception occurs."),(0,l.kt)("p",null,"An example of uploading files by using the write file stream interface is as follows:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'let vault = try Vault(appContext, providerAddress)\nlet filesService = try vault.filesService\nfilesService.getUploadWriter(YOUR_REMOTE_PATH)\n.then { fileWriter in\n return try fileWriter.write(data: REMOTE_FILE_CONTENT_DATA)\n}\n.done { success in\n print("Upload the file by writer successfully")\n}\n.catch { error in\n print("Failed to upload a file.")\n print(error)\n}\n')),(0,l.kt)("h2",{id:"download-file"},"Download File"),(0,l.kt)("p",null,"Similar to uploading files, when downloading them you can get the Reader or InputStream instance through the FileSerice instance, and then download the file data in the Vault based on the Reader instance or InputStream instance."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'filesService.getDownloadReader(YOUR_REMOTE_PATH)\n.then { fileReader in\n return fileReader.read(localCachePath)\n}\n.done { result in\n print("Download the file by input stream successfully")\n}\n.catch { error in\n print("Failed to download the file by input stream")\n print(error)\n}\n')),(0,l.kt)("h2",{id:"list-files"},"List Files"),(0,l.kt)("p",null,"List the files in the file directory. FileInfo is single file information, and path is the file directory:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'filesService!.list(YOUR_REMOTE_PATH)\n.done { list in\n print("List folder files successfully.")\n list.forEach { info in\n print("file name => \\(info.updated)")\n print("file size => \\(info.size)")\n }\n}\n.catch { error in\n print("Failed to list folder files")\n print(error)\n}\n')),(0,l.kt)("h2",{id:"stat"},"Stat"),(0,l.kt)("p",null,"Retrieve the information of a single file:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'filesService!.stat(YOUR_REMOTE_PATH)\n.done { fileInfo in\n print("get the state of the file successfully.")\n print("file name => \\(fileInfo.name)")\n print("file size => \\(fileInfo.size)")\n}\n.catch { error in\n print(error)\n}\n')),(0,l.kt)("h2",{id:"move"},"Move"),(0,l.kt)("p",null,"Move a single file from source to target:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'filesService!.move(YOUR_REMOTE_PATH, YOUR_REMOTE_NEW_PATH)\n.done { success in\n print("Moved the file to new path in success.")\n}\n.catch { error in\n print("Failed to move the file")\n print(error)\n}\n')),(0,l.kt)("h2",{id:"delete"},"Delete"),(0,l.kt)("p",null,"Delete the file; the file is in the path:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-js"},'filesService!.delete(YOUR_REMOTE_PATH)\n.done { success in\n print("Delete the file successfully")\n}\n.catch { error in\n print("Failed to delete of the file")\n print(error)\n}\n')))}h.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.