I upload an image in SharePoint:
I save the image file in the folder: IMAGES\\imagewebpart\\
Random rd = new Random();
int db = rd.Next(0, 100);
string filename =Path.GetFileNameWithoutExtension(imagefile) +
db.ToString() +
Path.GetExtension(imagefile);
string filepath ="\\_layouts\\IMAGES\\imagewebpart\\" + filename;
FileUpload1.SaveAs(Server.MapPath(filepath));
//ImageEdit.ImageUrl =filepath;
ImageEdit.ImageUrl = Server.MapPath(filepath);
I can save the file successfully, but I can't display the image to ImageEdit.
Why?
ImageEdit.ImageUrl = Server.MapPath(filepath);
Try this
ImageEdit.ImageUrl = filepath;
where filepath = "/_layouts/IMAGES/imagewebpart/" + filename
Related
Am trying to download multiple PDF files from Azure and combine them (using PyPDF2 library) all into one PDF for re-upload into azure.
Am currently getting an error of PyPDF2.utils.PdfReadError: Unsupported PNG filter 4 on line pdf = PyPDF2.PdfFileReader(output).
consolidated_pdf = review_level_str.title() + '.pdf'
merger = PyPDF2.PdfFileMerger()
for each_file in filename_lst:
blob_client = blob_service.get_blob_client(container=f'{flask_env}-downloads', blob=each_file)
blob_object = blob_client.download_blob()
bytes_file = blob_object.readall()
output = io.BytesIO()
output.write(bytes_file)
pdf = PyPDF2.PdfFileReader(output)
merger.append(pdf)
blob_client_pdf = blob_service.get_blob_client(container=f'{flask_env}-downloads', blob=consolidated_pdf)
blob_client_pdf.upload_blob(pdf.getvalue())
Try this:
from azure.storage.blob import ContainerClient
from PyPDF2 import PdfFileMerger
import shutil,os
pdf_list = ['test1.pdf','test2.pdf']
container = 'pdf'
storage_conn_str = ''
tempPath = 'd:/home/temp2/'
os.mkdir(tempPath)
mergedObject = PdfFileMerger()
ContainerClient = ContainerClient.from_connection_string(storage_conn_str,container)
for pdf in pdf_list:
localPdfPath = tempPath + pdf
with open(localPdfPath, "wb") as download_file:
download_file.write(ContainerClient.download_blob(pdf).readall())
mergedObject.append(localPdfPath)
mergedPDFPath = tempPath + 'merged.pdf'
mergedObject.write(mergedPDFPath)
mergedObject.close()
with open(mergedPDFPath, "rb") as stream:
ContainerClient.upload_blob('merged.pdf',stream, overwrite=True)
#remove all temp files after upload.
shutil.rmtree(tempPath)
Result:
Check the merged.pdf:
Let me know if you have any more questions.
I have a legacy classic asp application, that allows us to upload pdf files. The file is saved as hex into a MS SQL DB into an image column. Here is a snip of the data in the column:
0x4A564245526930784C6A634E436957317462573144516F784944416762324A7144516F...
We are now working on a rework of the app using node.js as our backend and angular4 as the front end. As part of that, we need to be able to download the same file in the new app. If I upload the same file using angular4 then the image data looks like this:
0x255044462D312E370D0A25B5B5B5B50D0A312030206F626A0D0A3C3C2F547970652F43...
As you can see the hex is completely different and I am not sure what is causing this. I have tried to look at the classic asp code, but its very old and there is no special encoding or such that is happening that would cause this.
In Angular4 we are using the standard input type file control with the change event to capture the contents of the file and then saving it into our db:
myReader.onloadend = (f) => {
let image64;
if (myReader.result.toString()) {
let base64id = ';base64,';
image64 = myReader.result.substr(myReader.result.indexOf(base64id) + base64id.length);
}
someService.upload(image64);
}
So nothing crazy going on, right? The problem now is that I am able to download the file uploaded via angular fine, but not the ones that were uploaded via classic asp. I receive the following error when I try:
Failed to execute 'atob' on 'Window': The string to be decoded is not
correctly encoded.
Here is the code used to upload the files via classic ASP:
Public Function Load()
Dim PosBeg, PosEnd, PosFile, PosBound, boundary, boundaryPos, Pos
Dim Name, Value, FileName, ContentType
Dim UploadControl
PosBeg = 1
PosEnd = InstrB(PosBeg,m_FormRawData,getByteString(chr(13)))
boundary = MidB(m_FormRawData,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,m_FormRawData,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(m_FormRawData,boundary & getByteString("--")))
Set UploadControl = Server.CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,m_FormRawData,getByteString("Content-Disposition"))
Pos = InstrB(Pos,m_FormRawData,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,m_FormRawData,getByteString(chr(34)))
Name = getString(MidB(m_FormRawData,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,m_FormRawData,getByteString("filename="))
PosBound = InstrB(PosEnd,m_FormRawData,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,m_FormRawData,getByteString(chr(34)))
FileName = getString(MidB(m_FormRawData,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,m_FormRawData,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,m_FormRawData,getByteString(chr(13)))
ContentType = getString(MidB(m_FormRawData,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,m_FormRawData,boundary)-2
Value = MidB(m_FormRawData,PosBeg,PosEnd-PosBeg)
UploadControl.Add "value" , Value
m_dicFileData.Add LCase(name), UploadControl
Else
Pos = InstrB(Pos,m_FormRawData,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,m_FormRawData,boundary)-2
Value = getString(MidB(m_FormRawData,PosBeg,PosEnd-PosBeg))
UploadControl.Add "value" , Value
End If
m_dicForm.Add LCase(name), UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),m_FormRawData,boundary)
Loop
Load = m_blnSucceed
End Function
Any idea what I can do here to fix this? I need to be able to download the old files as well. Is there an encoding or something else I am missing here?
After further looking into this, it seems the following is causing the error: Node.js will send a buffer to the front-end. On the front-end I then convert the buffer into base64 using the below code:
_arrayBufferToBase64(buffer) {
let base64 = '';
let bytes = new Uint8Array(buffer);
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
bbase64 += String.fromCharCode(bytes[i]);
}
return base64;
}
The returned base64 from the old classic asp is returned as garbage and looks like this:
*R{£ÌõGpÃì#j¾é>i¿ê A l Ä ð!!H!u!¡!Î!û"'"U""¯"Ý#
(?(q(¢(Ô))8)k))Ð5*hÏ++6+i++Ñ,,9,n,¢,×-''I'z'«'Ü(
3F33¸3ñ4+4e44Ø55M55Â5ý676r6®6é7$7`77×88P88È99B99¼9ù:6:t
I am still not sure how to fix this though.
I need to write an excel file to many folders ( folder* ) under D:\ and loop over them to further process individually.
i tried the following code for long time ..
srcFolders = dir('D:\folder*');
for i = 1 : length(srcFiles)
filename = strcat(path,'\',srcFiles(i).name);
xlswrite('srcFolders\filename.xls', srcFolders(folder).name,'Sheet1', folder_range);
end
I'm assuming that you want to write different sets of data to a Excel file and were just having some trouble. If that's not accurate comment and let me know.
%Just generating some arbitrary data
data = arrayfun(#(m,n) rand(m,n), randi(50, 9, 1), randi(50, 9, 1), 'uni', 0);
%The base file path
path = 'D:';
%The pattern used to choose the folders
folderPattern = 'folder*';
%The files you want to write to
srcFiles = {'A', 'B', 'D'};
%And the extension
ext = '.xlsx';
%Get the path of the folders
srcFolders = dir(fullfile(path, folderPattern));
srcFolders = fullfile(path, {srcFolders.name});
%Construct the full file path
fullPath = cellfun(#(f) fullfile(f, strcat(srcFiles(:), ext)), srcFolders, 'uni', 0);
fullPath = vertcat(fullPath{:});
%Write the data to the files
for i = 1:length(fullPath)
xlswrite(fullPath{i}, data{i})
end
Edit:
Based on OP's feed.
Note for the second overhaul. I didn't test this and I'm done. This was way to much for a single question and you are abusing the way this website is supposed to work.
%The base file path
path = 'D:';
%Relative reference to reference images
ImageRefLocations = {'Ref\RefI1.jpg', 'Ref\RefI2.png', 'Ref\RefI3.jpg'};
%Base Image location
baseImage = fullfile(path, ImageRefLocations(:));
%The pattern used to choose the folders
folderPattern = 'folder*';
%The image extension
[~, ~, ext] = unique(cellfun(#(f) fileparts(f), baseImage, 'uni', 0));
%The excel extension
ExcelExt = '.xlsx';
msg = {' = no'; ' = ok'};
i0 = cellfun(#(f) imread(f), baseImage, 'uni', 0);
%Get the path of the folders
srcFolders = dir(fullfile(path, folderPattern));
isDir = [srcFolders.isdir];
srcFolders = {srcFolders(isDir).name}';
PathedFolders = fullfile(path, srcFolders);
excelFiles = fullfile(path, strcat(srcFolders, ExcelExt));
for i = 1:length(PathedFolders)
f = PathedFolders{i};
Images = cellfun(#(x) dir(fullfile(f, ['*', x])), ext, 'uni', 0);
Images = vertcat(Images{:});
if isempty(Images)
continue
end
Images = {Images.name}';
[~, ImageNames, ~] = cellfun(#(x) fileparts(x), Images, 'uni', 0);
ImageList = fullfile(f, Images);
match = zeros(size(ImageList));
for j = 1:length(ImageList)
image = imread(ImageList{j});
for k = 1:length(i0)
if ~all(size(image) == size(i0{k}))
continue
end
match(j) = all(image(:) == i0{k}(:));
if match(j)
continue
end
end
end
matchMessage = strcat(Images, msg(match + 1));
xlswrite(excelFiles{i}, matchMessage)
end
My code is not working and not giving any exception:
OutputConnection con = (OutputConnection) Connector.open("file:///epsd/rescuer.txt", Connector.WRITE);
System.out.println("below con");
OutputStream out = con.openOutputStream();
PrintStream ps = new PrintStream(out);
System.out.println("below ps");
ps.println(name+"!"+no+"!"+"!"+mtype+"!#!");
System.out.println("below println");
ps.close();
con.close();
Control doesn't reach after OutputConnection line. Is this how to append data to a text file in J2ME?
Use the following to get the SDCard path and concat it with your file name
String memoryCardPath = System.getProperty("fileconn.dir.memorycard");
String filePath = memoryCardPath + "/rescuer.txt";
OutputConnection con = (OutputConnection) Connector.open(filePath, Connector.WRITE);
I have a string with length no more than 4000 chars which is a valid xml. Is there a way to pass it to Dataset without creating a temporary xml file?
At the moment I do so:
string validXml = TextBox1.Text;
string path = Directory.GetCurrentDirectory() + #"\tmp.xml";
FileInfo xmlProcess = new FileInfo(path);
using (StreamWriter sw = xmlProcess.CreateText())
{
sw.WriteLine(validXml);
}
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(reader);
Is there a way to skip this creating and filling the tmp.xml?
Try this:
XmlTextReader reader = new XmlTextReader(new StringReader(validXml));
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(reader);