Exemple #1
0
        /// <summary>
        /// Gets the URL location of an attachment
        /// </summary>
        public async Task <string> RetrieveAttachmentDownloadUrl(CancellationToken token, ulong attachmentId)
        {
            string path = string.Format(ATTACHMENT_PATH, attachmentId.ToString());

            string response = await MakeServiceRequestAsync(token, path, "GET", null);

            AttachmentDescriptor descriptor = JsonUtil.FromJson <AttachmentDescriptor>(response);

            return(descriptor.Location);
        }
Exemple #2
0
        /// <summary>
        /// Gets a URL that can be used to upload an attachment
        /// </summary>
        /// <returns>The attachment ID and the URL</returns>
        public async Task <(ulong id, string location)> RetrieveAttachmentUploadUrl(CancellationToken token)
        {
            string response = await MakeServiceRequestAsync(token, string.Format(ATTACHMENT_PATH, ""), "GET", null);

            AttachmentDescriptor attachmentKey = JsonUtil.FromJson <AttachmentDescriptor>(response);

            if (attachmentKey == null || attachmentKey.Location == null)
            {
                throw new Exception("Server failed to allocate an attachment key!");
            }
            return(attachmentKey.Id, attachmentKey.Location);
        }
        public Tuple <ulong, byte[]> SendAttachment(PushAttachmentData attachment)// throws IOException
        {
            string response = makeRequest(string.Format(ATTACHMENT_PATH, ""), "GET", null);
            AttachmentDescriptor attachmentKey = JsonUtil.fromJson <AttachmentDescriptor>(response);

            if (attachmentKey == null || attachmentKey.getLocation() == null)
            {
                throw new Exception("Server failed to allocate an attachment key!");
            }

            Debug.WriteLine("Got attachment content location: " + attachmentKey.getLocation(), TAG);

            byte[] digest = UploadAttachment("PUT", attachmentKey.getLocation(), attachment.getData(),
                                             attachment.getDataSize(), attachment.getKey());

            return(new Tuple <ulong, byte[]>(attachmentKey.getId(), digest));
        }
        public void retrieveAttachment(string relay, ulong attachmentId, FileStream tmpDestination, int maxSizeBytes)
        {
            string path = string.Format(ATTACHMENT_PATH, attachmentId.ToString());

            if (!Util.isEmpty(relay))
            {
                path = path + "?relay=" + relay;
            }

            string response = makeRequest(path, "GET", null);

            Debug.WriteLine("PushServiceSocket: Received resp " + response);
            AttachmentDescriptor descriptor = JsonUtil.fromJson <AttachmentDescriptor>(response);

            Debug.WriteLine("PushServiceSocket: Attachment: " + attachmentId + " is at: " + descriptor.getLocation());

            downloadExternalFile(descriptor.getLocation(), tmpDestination);
        }
Exemple #5
0
        public async Task <ulong> sendAttachment(PushAttachmentData attachment)// throws IOException
        {
            string response = await makeRequest(string.Format(ATTACHMENT_PATH, ""), "GET", null);

            AttachmentDescriptor attachmentKey = JsonUtil.fromJson <AttachmentDescriptor>(response);

            if (attachmentKey == null || attachmentKey.getLocation() == null)
            {
                throw new Exception("Server failed to allocate an attachment key!");
            }

            Debug.WriteLine("Got attachment content location: " + attachmentKey.getLocation(), TAG);

            /*uploadAttachment("PUT", attachmentKey.getLocation(), attachment.getData(),
             *               attachment.getDataSize(), attachment.getKey());
             */
            throw new NotImplementedException("PushServiceSocket sendAttachment");
            return(attachmentKey.getId());
        }