Changeset 11903


Ignore:
Timestamp:
Aug 3, 2011, 5:48:31 PM (13 years ago)
Author:
bayral
Message:

pwg.image.addImage work fine.

Location:
extensions/PiwigoLib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgBase64Helper.cs

    r11890 r11903  
    1212            try
    1313            {
    14                 string encodedData = Convert.ToBase64String(encData_byte);
     14                String encodedData = String.Empty;
     15                encodedData = Convert.ToBase64String(encData_byte);
     16                //encodedData = Encoding.UTF8.GetString(encData_byte, 0, encData_byte.Length);
    1517                return encodedData;
    1618            }
  • extensions/PiwigoLib/PiwigoLib/Proxy/PwgImagesProxy.cs

    r11890 r11903  
    3232 * */
    3333
    34         static internal PwgBaseProxyReponse pwg_images_add(String fileGuid, String thunbGuid, String HighresGuid,
    35             String imageGuid,  String imageFilename, String imageName, String imageAuthor, DateTime creationDate, 
     34        static internal PwgBaseProxyReponse pwg_images_add(String fileMd5sum, String thunbMd5sum, String HighresMd5sum,
     35            String imageMd5sum,  String imageFilename, String imageName, String imageAuthor, DateTime creationDate, 
    3636            String authorComment,List<String> lstCategories, List<String> lstTags, PwgConfidentLevelEnum? confidentLevel)
    3737        {
     
    4242                data.Append("method=pwg.images.add");
    4343                Boolean firstOcc = false;
    44                 PwgProxyReponseHelper.buildQueryFromValue<String>(fileGuid, "file_sum", ref firstOcc, data);
    45                 PwgProxyReponseHelper.buildQueryFromValue<String>(thunbGuid, "thumbnail_sum", ref firstOcc, data);
    46                 PwgProxyReponseHelper.buildQueryFromValue<String>(HighresGuid, "high_sum", ref firstOcc, data);
    47                 PwgProxyReponseHelper.buildQueryFromValue<String>(imageGuid, "original_sum", ref firstOcc, data);
     44                PwgProxyReponseHelper.buildQueryFromValue<String>(fileMd5sum, "file_sum", ref firstOcc, data);
     45                PwgProxyReponseHelper.buildQueryFromValue<String>(thunbMd5sum, "thumbnail_sum", ref firstOcc, data);
     46                PwgProxyReponseHelper.buildQueryFromValue<String>(HighresMd5sum, "high_sum", ref firstOcc, data);
     47                PwgProxyReponseHelper.buildQueryFromValue<String>(imageMd5sum, "original_sum", ref firstOcc, data);
    4848                PwgProxyReponseHelper.buildQueryFromValue<String>(imageFilename, "original_filename", ref firstOcc, data);
    4949                PwgProxyReponseHelper.buildQueryFromValue<String>(imageName, "name", ref firstOcc, data);
  • extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs

    r11890 r11903  
    4848            return returnValue;
    4949        }
    50 
     50       
    5151        public PwgImageAdded addImageByMultiPartForm(FileInfo fileImage, Int32? imageId, Int32? categoryId, String imageName, String imageAuthor, String imageComment, Int32? imageLevel, List<PwgTag> imageTags)
    5252        {
     
    8989            try
    9090            {
    91                 String fileGuid =  uploadImageByChunk(lowResFile, PwgFileTypeEnum.LowRes);
    92                 String thunbGuid = uploadImageByChunk(thumbFile, PwgFileTypeEnum.Thumb);
    93                 String HighresGuid = uploadImageByChunk(highResFile, PwgFileTypeEnum.HighDef);
    94                 String imageGuid = (highResFile != null ? HighresGuid : fileGuid);  //Guid.NewGuid().ToString();
     91                String fileMd5sum =  uploadImageByChunk(lowResFile, PwgFileTypeEnum.LowRes, null);
     92                String thunbMd5sum = uploadImageByChunk(thumbFile, PwgFileTypeEnum.Thumb, fileMd5sum);
     93                String HighresMd5sum = uploadImageByChunk(highResFile, PwgFileTypeEnum.HighDef, fileMd5sum);
     94                String imageMd5sum = fileMd5sum; //(highResFile != null ? HighresMd5sum : fileMd5sum);  //Md5sum.NewMd5sum().ToString();
    9595                String imageFilename = (highResFile != null ? highResFile.Name : lowResFile.Name);
    9696
    97                 PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_add( fileGuid, thunbGuid, HighresGuid,
    98                                                     imageGuid,  imageFilename, imageName, imageAuthor, creationDate, 
     97                PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_add( fileMd5sum, thunbMd5sum, HighresMd5sum,
     98                                                    imageMd5sum,  imageFilename, imageName, imageAuthor, creationDate, 
    9999                                                    authorComment, lstCategories, lstTags, confidentLevel);
    100100
     
    124124        }
    125125
    126         public String uploadImageByChunk(FileInfo imageFile, PwgFileTypeEnum fileType)
     126        public String uploadImageByChunk(FileInfo imageFile, PwgFileTypeEnum fileType, String InitialMd5sum)
    127127        {
    128128            byte[] buffer = new byte[5000];
    129             string strGuid = String.Empty; ;
     129            string strMd5sum = String.Empty; ;
    130130            int read;
    131131            int chunkNumber = 1;
     
    136136                {
    137137                    FileStream fs = File.OpenRead(imageFile.FullName);
    138                     strGuid = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.GetphpMd5Sum(fs);
     138                    strMd5sum = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.GetphpMd5Sum(fs);
     139                    // if not checksum was provide we use the one computed for transfert
     140                    if (String.IsNullOrWhiteSpace(InitialMd5sum))
     141                    {
     142                        InitialMd5sum = strMd5sum;
     143                    }
    139144                   
    140145                    fs.Seek(0, SeekOrigin.Begin);
    141                     while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
    142                     {
    143                         String strB64Data = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.base64Encode(buffer);
    144                         PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_addChunk(strB64Data, strGuid, fileType, chunkNumber);
     146                    while ((read = fs.Read(buffer, 0, 5000)) > 0)
     147                    {
     148                        byte[] truncBuffer;
     149                        // si on est arriver àla fin du fichier et que le tableau fait moins de 50000 , on le tronque en le copiant
     150                        // sinon on recopie l'adresse
     151                        if (read < 5000)
     152                        {
     153                            truncBuffer = new Byte[read];
     154                            Array.Copy(buffer, truncBuffer, read);
     155                        }
     156                        else
     157                        {
     158                            truncBuffer = buffer;
     159                        }
     160
     161                        String strB64Data = Com.Piwigo.Lib.Proxy.Helper.PwgBase64Helper.base64Encode(truncBuffer);
     162                        PwgBaseProxyReponse response = PwgImagesProxy.pwg_images_addChunk(strB64Data, InitialMd5sum, fileType, chunkNumber);
    145163
    146164                        chunkNumber += 1;
     
    163181                else
    164182                {
    165                     strGuid = String.Empty;
     183                    strMd5sum = String.Empty;
    166184                }
    167185            }
     
    170188                throw new PwgServiceException("uploadImageByChunk : a error is raised by proxy.", ex);
    171189            }
    172             return strGuid;
     190            return strMd5sum;
    173191        }
    174192
  • extensions/PiwigoLib/TestPiwigoLib/Form1.cs

    r11901 r11903  
    7474                //lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetAdminListOfCategory();
    7575
    76                 //FileInfo fiBig = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg");
    77                 //FileInfo fiThumb = new FileInfo(MakeThumb(fiBig,"C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_thum.jpg",64));
    78                 //FileInfo fiLow = new FileInfo(MakeThumb(fiBig,"C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_low.jpg",256));
     76                FileInfo fiBig = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg");
     77                FileInfo fiThumb = new FileInfo(MakeThumb(fiBig, "C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_thum.jpg", 64));
     78                FileInfo fiLow = new FileInfo(MakeThumb(fiBig, "C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_low.jpg", 256));
    7979
    80                 FileInfo fiBig = new FileInfo("C:\\temp\\Oryx.jpg");
    81                 FileInfo fiThumb = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_thumb.jpg", 64));
    82                 FileInfo fiLow = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_low.jpg", 256));
     80                //FileInfo fiBig = new FileInfo("C:\\temp\\Oryx.jpg");
     81                //FileInfo fiThumb = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_thumb.jpg", 64));
     82                //FileInfo fiLow = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_low.jpg", 256));
    8383
    8484                //PwgImageAdded imgAdd = PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fiBig, null, 1, "benoit", "byarl", "test upload", 0, new List<PwgTag>() { new PwgTag() { Name = "Benoit" }, new PwgTag() { Name = "Noé" } });
    85                 rc = PwgServiceProvider.Instance.PwgImagesService.addImage(fiBig, fiLow, fiThumb, "Benoit", "bayral", DateTime.Now, "demo", null, null, PwgConfidentLevelEnum.All);
     85                rc = PwgServiceProvider.Instance.PwgImagesService.addImage(fiBig, fiLow, fiThumb, "Benoit", "bayral", DateTime.Now, "demo", new List<string>() { "1" }, new List<string>() { "Benoit" }, PwgConfidentLevelEnum.All);
    8686                //rc = PwgServiceProvider.Instance.PwgImagesService.DeleteImage(319, sess.SecurityToken);
    8787
Note: See TracChangeset for help on using the changeset viewer.