/// <summary> /// pwg.images.addChunk /// </summary> /// <param name="strb64Data"></param> /// <param name="uniqueId"></param> /// <param name="fileType"></param> /// <param name="?"></param> /// <param name="chunckNumber"></param> /// <returns></returns> internal static PwgBaseProxyReponse pwg_images_addChunk(String strb64Data, String uniqueId, PwgFileTypeEnum fileType, Int32 chunckNumber ) { PwgBaseProxyReponse response = null; try { StringBuilder data = new StringBuilder(); data.Append("method=pwg.images.addChunk"); Boolean firstOcc = false; PwgProxyReponseHelper.buildQueryFromValue<String>(strb64Data, "data", ref firstOcc, data); PwgProxyReponseHelper.buildQueryFromValue<String>(uniqueId, "original_sum", ref firstOcc, data); PwgProxyReponseHelper.buildQueryFromValue<PwgFileTypeEnum>(fileType, "type", ref firstOcc, data); PwgProxyReponseHelper.buildQueryFromValue<Int32>(chunckNumber, "position", ref firstOcc, data); response = PwgGenericProxy<PwgBaseProxyReponse>.Post( PwgConfigProxy.PwgServeurUri, data.ToString()); } catch (Exception ex) { throw new PwgProxyException("pwg_images_rate", ex); } return response; }
public String uploadImageByChunk(FileInfo imageFile, PwgFileTypeEnum fileType, String InitialMd5sum) { byte[] buffer = new byte[5000]; string strMd5sum = String.Empty; ; int read; int chunkNumber = 1; try { if (imageFile != null) { FileStream fs = File.OpenRead(imageFile.FullName); strMd5sum = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.GetphpMd5Sum(fs); // if not checksum was provide we use the one computed for transfert if (String.IsNullOrWhiteSpace(InitialMd5sum)) { InitialMd5sum = strMd5sum; } fs.Seek(0, SeekOrigin.Begin); while ((read = fs.Read(buffer, 0, 5000)) > 0) { byte[] truncBuffer; // si on est arriver àla fin du fichier et que le tableau fait moins de 50000 , on le tronque en le copiant // sinon on recopie l'adresse if (read < 5000) { truncBuffer = new Byte[read]; Array.Copy(buffer, truncBuffer, read); } else { truncBuffer = buffer; } String strB64Data = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.base64Encode(truncBuffer); PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_addChunk(strB64Data, InitialMd5sum, fileType, chunkNumber); chunkNumber += 1; if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok) { if (response.Erreur != null) { throw new PwgServiceException("uploadImageByChunk, the server has return the error.", response.Erreur.Code, response.Erreur.Message); } else { throw new PwgServiceException("uploadImageByChunk : a error occurs during server process."); } } } } else { strMd5sum = String.Empty; } } catch (PwgProxyException ex) { throw new PwgServiceException("uploadImageByChunk : a error is raised by proxy.", ex); } return strMd5sum; }