Example #1
0
        public async Task<int> Post(FileShim file,
                                    CancellationToken cancelToken,
                                    string serverFoldr,
                                    bool isPrivate)
        {
            if (!IsLoggedIn)
                throw Error.BadAct($"‹{this.GetType().Name}› is not logged in.");

            Trace_n("Uploading file to server...", "");
            var req = _auth.Req.POST(URL.Api_FileJson);

            req.Body = new D7File_Out(file,
                            serverFoldr, isPrivate);

            D7File d7f = null; try
            {
                d7f = await _client.Send<D7File>(req, cancelToken, null,
                    "Successfully uploaded “{0}” ({1}) [fid: {2}].",
                        x => file.Name, x => file.Size.KB(), x => x.fid);
            }
            catch (RestServiceException ex) { OnFileUpload.Err(this, ex); }
            catch (Exception ex) { OnUnhandled.Err(this, ex); }


            if (d7f != null && d7f.fid > 0) return d7f.fid;
            else if (d7f == null) return Error_(-1, "Returned null.", "");
            else return Error_(-1, "Unexpected file id: " + d7f.fid, "");
        }
Example #2
0
        public D7File_Out(FileShim fShim,
                          string serverFoldr,
                          bool isPrivate)
        {
            //if (!fShim.Found) Throw.Missing(fShim);
            var defLevl = fShim.DefaultLevel;

            fShim.DefaultLevel = L4j.Off;

            var fPath = isPrivate ? "private://" : "public://";

            fPath = fPath.Slash(serverFoldr).Slash(fShim.Name);

            this.file = new D7File
            {
                file     = fShim.ToBase64,
                filename = fShim.Name,
                filepath = fPath,
                //status   = Constants.FILE_STATUS_PERMANENT,
                //filemime = "application/x-msdos-program"
                //filemime = 149
            };

            fShim.DefaultLevel = defLevl;
        }
Example #3
0
 public static byte[] Bytes(this D7File d7FileDto)
 {
     return(Convert.FromBase64String(d7FileDto.file));
 }