function UploadFile(FileName, options) { // Как без таких извратов писать в лог!? function writelog(data) { local mylog = file("mylog.log","ab"); data = "" + data; // tostring local b = blob(data.len()); for(local i=0; i<data.len(); i++) { b[i]=data[i]; }; mylog.writeblob(b); b = blob(2); b[0] = 13; b[1] = 10; mylog.writeblob(b); } //system("cmd") //system("C:\\WINDOWS\\system32\\notepad.exe") function getFileSize(filename) { local f = file(filename,"rb"); return f.len(); // There is no function to close the file? } writelog("-----------------------------------------------------------------") //local newName = FileName + ".jpg"; local newName = getenv("TEMP") + "\\tmd_iu_temp\\" + ExtractFileName(FileName) + ".jpg"; writelog("FileName="+FileName); writelog("newName="+newName); system("gm convert -sampling-factor 4:4:4 -quality 86 " + FileName + " " + newName); local oldLength = getFileSize(FileName) local newLength = getFileSize(newName) writelog("oldLength="+oldLength); writelog("newLength="+newLength); local selectedFile = (oldLength/newLength >=2) ? newName : FileName; nm.setUrl("http://ipic.su/"); nm.addQueryParam("link","/"); nm.addQueryParam("action","loadimg"); nm.addQueryParam("client","ipic.su"); nm.addQueryParamFile("image",selectedFile, ExtractFileName(selectedFile),""); nm.addQueryParam("name",""); nm.addQueryParam("desc",""); nm.addQueryParam("origin","on"); nm.addQueryParam("cropselect","800"); nm.addQueryParam("quality","85"); nm.doUploadMultipartData(); local data = nm.responseBody(); local ex = regexp("\\[url=(.*)\\]\\[img\\](.*)\\[/img\\]\\[/url\\]"); local res = ex.capture(data, 0); if(res == null){ return 0 } local directUrl = ""; local thumbUrl = ""; directUrl = data.slice(res[1].begin, res[1].end); thumbUrl = data.slice(res[2].begin, res[2].end); options.setDirectUrl(directUrl); options.setThumbUrl(thumbUrl); return 1; } |