oracle procedure save clob as image - oracle

I am having issues trying to save a base64 string to a file on my server
below is the base64 which is over the 32k limit so trying to figure out how to save it.
I can seccessfuly save the file on my server but when I try to open it its not readable its a png image.
if (resp.extract('//GetPostageLabelResponse/LabelRequestResponse/Label/Image', vNameSpace) is not null) then
dbms_lob.createtemporary(vBase64, false);
vBase64 := resp.extract('//GetPostageLabelResponse/LabelRequestResponse/Label/Image',vNameSpace ).getclobval();
DBMS_OUTPUT.PUT_LINE('Length of Image: '||length(vBase64));
DBMS_XSLPROCESSOR.clob2file(cl => vBase64, flocation => 'TEST', fname => vShipReqId||'.png');
iVBORw0KGgoAAAANSUhEUgAABtsAAASDCAIAAACXxhfdAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAALiMAAC4jAXilP3YAAP+lSURBVHhe7J0HoBTFskDxKYLkm3NOJFFUjIgJAdFnQsCEOecACgiKot+AEVFRMeszZ8UASJCoGMggOeecw8VfO10z2zPT3dOz6e5e6vz9+3a6q6uqq8P0lMvdGgRBEARBEARBEARBEARBEBHnXwlYTRAEQRAEQRAEQRAEQRAEEUEwAekCqwmCIAiCIAiCIAiCIAiCICIIJiBdYDWABQRBEARRpeBtKVY3JjRG98G4Ya8BXhBE4oNbDG0yBEEQBEEcSOABiDKSBEEQRKKAtyXKSFYX9u/fj5/+/XfPnj379u3jS9yADIAXBJH44BZDmwxBEARBEAcSeACijCRBEASRKOBtiTKS1YLKyso9e/bs3bt3165dW7duXbly5apVq9auXbtx40a43L59O5RDLYhhA8pIEtUO3GJokyEIgiAI4kACD0CUkSQIgiASBbwtUUayWrB79+4tW7bAh3379m3YsGHBggXz589ftGjRihUr1q9fv23bNj4XaUH/apuoTuAWQ5sMQRAEQRAHEngAoowkQRAEkSjgbYkyktWCnTt3rlmzZuvWrcuWLZs8efLQoUO//vrr77//fsSIERMmTJgxYwaUQy1KmwjTlASRoOAWQ5sMQRAEQRAHEngAoowkQRAEkSjgbYkyktWCHTt2LF++fMGCBRMnTvzggw+eeuqp/v37P/74488///wbb7zx5Zdfjhs37p9//tmwYQM2MP7upPoPTRJEYoFbDG0yBEEQBEEcSOABiDKSBEEQRKKAtyXKSFYLduzYsXTp0mnTpg0dOnTAgAG33nrrVVdddd111915550PPvjgiy+++MUXX0yaNGnJkiX79u3DNgRRvcAthjYZgiAIgiAOJPAAVH0ykiO7o7sc3UdipQubdIchi7DYAS8l1rVoSAesN5EqM/ArHx1Cj1V4Uu7eB9CNrAeyQIo663uUpH0SaBfr9tN3OcLOOFD0Tad5EFWQRJrCmxwaOGOoVqXbWfVcCOLHeqizVztQws559MTWRiobobGKHugbZSSrBbt27Vq6dOmff/756aef9u7du2vXrmefffb555/frVu322+//dFHH33nnXdGjRo1b948kMQ2AtzrQT53hWsniLChH/0B/MprbS4ejlsI17ZrS3KbCEO/hnY7DlseW1d1B6NAmwxBEES8gts0QRAhgQvJBVZrCMT7Icnz4V90NtY7D/NSLi0quyJ9fuWjQdixkj9nqKU8DbvaeLdw4IqhhgZJd4QthbKOeWTgdMR/3+WI7InRdleOcFZ69kZkWG8KeeE2rdTlr7Oebvmy7j3mDjDW3oHS0CzzyxEQyaYTmbGKIuhbrG5MaIySBdFhz549S5cu/e23395777077rijY8eObdq0adeu3UUXXXT99df37dt3yJAhw4YNmz179o4dO7CNHdU6F01grxXkbONXf+T8ca5QlWYe/TuQXTJE/fJm4v1D6o5kRzoAwADQJkMQBBGv4DZNEERI4EJygdUaAvF8SNJ4PDdwHXVdh2jh2ZmXsgt4Gw5PPgpEJFZyLxVSupZtzXQbWYT2cCXsktC26HHJWzCkvsvR7xbg9thXc3d73c64GupNIQ9EzosGxcRfZ9W6/FoPdfZ6BEq/S6Iou1oLh8LDhaoHfYvVjQmNUbIgOuzZs2fRokVjx4599dVXr7322jZt2rRq1erUU0+94IILrrvuuj59+rz++us///zzzJkzt23bhm04vBeaaw57LSJbA7/6ffvj4Y1NWnf5++oBJxyKfg/17i1SbcQRnQMF7D1tMgRBEPEKbtMEQY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Fq6wyg8icM6y60YiAWsrnsaUnql1C5TTpQrOVnVYK+xerGhMboDBodKisrly5dOn78+FdfffW6665ra3DFFVc8+uijn3322ZQpU9atW7dly5bt27fv3bsX28ixZnNIM9e7tV/94fhjtZWseE/dloBMwlzq4mpv39UeumvRnnQHU/tTnWH9BvCaIIgE559//unRo0dWVhau7Ro18vPz77vvvgULFqAEkWjgQNJGTRB+wGUjXzhYrSEQj2sveNYOoDrAskOu6wwseex26O0uluLhFekcpf3K89i9C6LWEq1Y2eGtSJ84JNhiomis4Yh+ZwGpsK0CHeLKuHnhrvTZfd2+I1pjIfdHs7kTaaBcMAOufoRo12HYA6dVuVG+JoDEpbCsu9CKgVhIP/6AXFjigaOBxqZXtaBvsboxoTE6g0aHysrKFStWTJ48+d13373jjjvOOuus0047rVOnTnffffdLL730008/zZgxY/HixStXrty8eTO2kWDOb+9tVIapQTzv/eoP2x+lAmvZShepp4QpEKJ+j3C59XvJe9VXX1i/AbyOOPv/3b9vH/zv6pWrhrz66sDnnx/04qDXXnsNltirr746aNCgV155BT48++yzb7zxxrp161ijPXv2wPvevXvZB3h3fFV56tSp06ZNW7hw4fTp02fPnv3PP//MMZhnACv3119/3bhxI0iy/5ywzwA+7K/cz/wJfPl5n/ErVfv//XXMmBeef/6lQS+9/NJLr4FXA18cOHAgeDh48GBw74knnhg/fnxA0kVAiQG73LRpE3gF1sElcGbmzJngHnyYO3cuvC9atGjChAmTJk0CSfb9a9bKwlJVaTi2feu2995913Bs0KuDX335pZfBvVdfGQzvr7z8Mrj48ssvQ2dBUvhtbv4SBMD6b7/9BvLgG3MPvJplsGDBAiifMmUKShMJDozs/fffn52djWu7Ro3CwsJevXrBekEJItHAgUzo06B1Z7fwPKG4m0hu0k5Bl5RTwDQdckPr1KDEVOcprD57uOMgCl1QShhYuw8Sg5aQ59gkBtgb+cLBag2BuFx79pkhn0W2wefE+HJba+mMFdmQaZfhV96BezkwPDSFGyu+vXR5SIR4nYqlxYvpOSiTsndWuZpt/bWJ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ySjU9GUoP3PoBZYeqCvQtVjcmNJaQZ9AEAJ4u4Glk9erV8LgCTzjw7AHPQsccc8zRRx99yimnwJPJXXfd9eijj8KTzzfffDNjxgx4voJne3gowvbWxNWYq9YSES5oawXYa33oN4i2PwyzqdpKcE8QyFn6RTq09Kv9FxlX2FS6U93Brkdjkwn8e+1A5uKDd9/LTE0rzi8ozS8sLSzKzc6pqKgoKCiA97y8vHr16l1yySXsX1hv376dpefgnaX+WXYS2LVrF1wuXrx4+PDhmzdvBhmWcdu3bx98YKlMEFi3bt3PP//Msm9WoaHA+GrV7j2V+yr37tm7Z9dusAFrv2vnLrUPrVVWUlpgpEoD6cj8gsblFWVlZVlZWeDeJ598AhoA5oAD5gYonz59==

Related

quote_from_bytes() expected bytes error when data is in bytes format when uploading to blob storage in Python3

Can someone tell me what I am doing wrong with trying to upload an image to blob storage? Below is my code.
print(type(img['image'])) #Output is <class 'bytes'>
connection_string = get_blob_connection_string()
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container="images", blob=img['id'])
exists = blob_client.exists()
if (exists == False):
result = blob_client.upload_blob(img['image'], blob_type="blockblob")
print(result)
When inserting the blob, it throws the error
quote_from_bytes() expected bytes
This error makes no sense, I gave it bytes. What am I missing?
After reproducing from my end, I have received the same issue. You are receiving this error because of incompatible type of the file (i.e., file format).
After changing the below line to the correct format I could able to achieve your requirement.
blob_client = blob_service_client.get_blob_client(container="images", blob=img['id'])
Below is the correct format
blob_client=blob_service_client.get_blob_client(container='container', blob='<LOCAL FILE PATH>');
Below is the complete code that worked for me
from azure.storage.blob import BlobServiceClient
from PIL import Image
connection_string = "<CONNECTION STRING>"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client=blob_service_client.get_blob_client(container='container', blob='<LOCALPATH>');
with open(file='<PATH IN YOUR STORAGE ACCOUNT WITH FILE NAME>', mode="rb") as data:
blob_client.upload_blob(data)
RESULTS:

Oracle APEX print with API

I need to export a report saving it in PDF format. I created a button that submits to a new page, which performs the following piece of code:
APEX_UTIL.DOWNLOAD_PRINT_DOCUMENT (
p_file_name => 'myreport123',
p_content_disposition => 'attachment',
p_application_id => :APP_ID,
p_report_query_name => 'MY_REPORT_QUERY',
p_report_layout_name => 'MY_REPORT_LAYOUT',
p_report_layout_type => 'xsl-fo',
p_document_format => 'pdf'
)
;
MY_REPORT_QUERY and MY_REPORT_LAYOUT are defined in the shared components. When I press the button, it downloads a pdf file, but it looks empty or corrupted.
What could be wrong? Do I need to specify the print server? And what about the field APP_ID?
I can confirm that both the query and layout work when I download the report by directly redirecting the page to the url of MY_REPORT_QUERY.
Thanks in advance and best regards.

Corrupted PDF When Saving to Database over 50kB

I have a webpage where the user can upload a PDF file and send it using AJAX to my Flask application. Here is the ajax code:
var formData = new FormData();
formData.append('attachment', document.getElementById("attachment").files[0]);
$.ajax({
type: 'POST',
url: 'process_award_storage',
contentType: false,
processData: false,
data: formData
})
I do not think that this has any problems because I can print out the content and title of file in the python code. Then my flask model is defined as such, using LargeBinary for the PDF attachment:
class AwardStore(db.Model):
__tablename__ = 'awards_store'
id = db.Column(db.Integer, primary_key=True)
...
file = db.Column(db.LargeBinary, nullable=True) #I am sure this is the right file type for PDF saving
Lastly, here is how the AJAX file is saved to the database:
award = AwardStore(name=name, file=request.files['attachment'].read())
db.session.add(award)
db.session.commit()
I can see using my MySQL Workbench that it is saved. However, when I try to download the BLOB from there to the Desktop and open it, it says "Failed to load PDF document". The same happens when I use flask's send_file. It seems like I did everything as I saw online, but something is wrong.
Maybe these warnings are related?:
C:\Users\msolonko\Desktop\NICKFI~1\CACHTM~1\APP_DE~1\virt\lib\site-packages\pymysql\cursors.py:170: Warning: (1300, "Invalid utf8 character string: 'C4E5F2'")
result = self._query(query)
C:\Users\msolonko\Desktop\NICKFI~1\CACHTM~1\APP_DE~1\virt\lib\site-packages\pymysql\cursors.py:170: Warning: (1265, "Data truncated for column 'file' at row 1")
result = self._query(query)
I tried googling them and did not find anything. I appreciate any assistance.
EDIT:
I noticed that small files are typically uploaded and displayed properly. The issue is with files with sizes > ~50kB. The database I am using the AWS RDS, Is there a setting I can change somewhere to enable greater sizes?
The LargeBinary accepts a length field also.
which converts to mysql's BLOB whose default length is 65535 bytes (64kb).
Try increasing the length and set it to
a MEDIUMBLOB for 16777215 bytes (16 MB)
a LONGBLOB for 4294967295 bytes (4 GB).
Hope this will help

Upload bytes or base64 string to s3 ruby sdk

I'm trying to upload an image to s3 using the ruby aws sdk. I'm able to upload the base64 string if I don't set the content_type. If I do set the content_type to image/png the upload is just the generic image thumbnail.
obj = #<Aws::S3::Object bucket_name="mybucket", key="test">
>> params[:file]
>> "data:image/png;base64,iVB...."
obj.put(body: params[:file], content_type: 'image/png', content_encoding: 'base64')
How can I upload a Base64 string to s3? I'm also open to uploading as bytes if that's more straight forward
I managed to get it to work with put, instead of upload_file. put makes more sense, since you are trying to upload an image encoded as a base64 data uri string.
Assuming your data uri string looks like:
string = 'data:image/jpeg;base64,<base_64_string>'
The key is to decode the <base_64_string> part and send it to body in the put method:
body = Base64.decode64(string.split(',')[1])
s3 = Aws::S3::Resource.new
s3.bucket(ENV['AWS_BUCKET_NAME']).object(key).put(body: body, acl: 'public-read', content_type: 'image/jpeg', content_encoding: 'base64')
This assumes you are using the the AWS Ruby library at https://github.com/aws/aws-sdk-ruby
I managed to solve this using the following code
file = params[:file]
s3 = Aws::S3::Resource.new
obj = s3.bucket('my_bucket').object("my_path").upload_file(file.tempfile)

How can I change chunk_size for Resumable Upload?

I need upload some big files(about 1Gb) into google drive.
I using google-api-client(ruby) version 0.5.0:
media = Google::APIClient::UploadIO.new(file_name, mimeType, original_name)
result = client.execute!(
:api_method => client.service.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'resumable',
'alt' => 'json'})
I expected that my client split big file on parts and upload these parts on drive.
But I see in logs, that client sending only ONE BIG chunk to drive.
Here is small log example:
Content-Length: "132447559"
Content-Range: "bytes 0-132447558/132447559"
How can I upload big files by chunks with google-api-client?
The intended usage is to try and upload the file in a single chunk. Overall, it's more efficient/faster that way. But there are cases where chunking is preferable, so if you need to chunk the upload for whatever reason, just set the chunk_size property:
media = Google::APIClient::UploadIO.new(file_name, mimeType, original_name)
media.chunk_size = 1000000 # 1mb chunks
result = client.execute!(....)
I'm using the API version 0.7.1, even though I know we're supposed to be using version 0.9 now, because the older version matches the Ruby examples on Google's documentation.
I had to do resort to uploading in chunks because I was getting errors in httpclient library complaining about the file size being too large to convert to integer!
Unfortunately, using #stevebazyl did not work for me as it only uploads the first chunk and then throws a TransmissionError. This seems to be in the google-api-ruby-client code, specifically, Google::APIClient class in the execute! method. It doesn't seem to be handling an HTTP status of 308, which is what a resumable upload returns when it needs the next chunk. I did this to the code:
when 200...300, 308
result
(See api_client.rb)
And use the #send_all method in the ResumableUpload class just like the sample code in the docs and it worked for me. So in addition to #stevebazyl code, I have:
media = Google::APIClient::UploadIO.new(opts[:file], 'video/*')
media.chunk_size = 499200000
videos_insert_response = client.execute!(
:api_method => youtube.videos.insert,
:body_object => body,
:media => media,
:parameters => {
:uploadType => 'resumable',
:part => body.keys.join(',')
}
)
videos_insert_response.resumable_upload.send_all(client)

Resources