How Can I Make My HTML Page Upload a PDF to my ASPX Page

Background

Application/Program: Lightweight Website (40,000 HTML Pages | 5 ASPX Pages)
Goal: HTML Functionality that sends Uploaded PDFs to an ASPX Page (for processing)
Problem: Uploaded PDFs Get Corrupted
Desire: Uncorrupted PDF Uploads


Tech Specs

Server Architecture: IIS 8.0 (Prod) | IIS 10.0 (Dev)
Client-Side: HTML; Javascript (Vanilla); AJAX
Server-Side: ASPX; Visual Basic
Connection/Communication: One Server/Domain (ie, the HTML pages are on the same website as the ASPX page)


Details

On my HTML page, I have a FileUpload control. I want website visitors to use that control to upload PDFs. I want to store those uploaded PDFs [directly] onto my server (in an actual directory).

To accomplish that, I want my HTML pages to “send” the users’ uploaded PDFs to my ASPX page. Whereby my ASPX page will perform the file storage.

Unfortunately, these uploaded PDFs end up getting corrupted [upon server storage]. They get corrupted in the following ways:

  1. The Uploaded PDFs Cannot Be Opened (typical error); or
  2. The Uploaded PDFs are missing content (eg, no text/image/content whatsoever; missing metadata).

Code

HTML Page

<form>
  <label for="inptFl" id="inptLbl"></label>
  <input type="file" name="inptFlNm" id="inptFl" accept=".pdf, application/pdf" multiple onchange="PickFiles();" />
  <button type="button" onclick="PushToServer();" >Submit</button>
</form>

Javascript

function PickFiles() {
  const flLst = document.getElementById("inptFl").files;
  var otPtLbl = document.getElementById("inptLbl");
  const flRdr = new FileReader();

  flRdr.addEventListener("load", (evnt) => {
    otPtLbl.setAttribute("data-loadedSource", evnt.target.result);
  });

  flRdr.ReadAsDataURL(flLst[0]);
  //flRdr.readAsBinaryString(flLst[0]);
}

function PushToServer() {
  const ajaxObj = new XMLHttpRequest();
  let otPtLbl = document.getElementById("inptLbl");
  let datURL = otPtLbl.getAttribute("data-loadedSource");

  ajaxObj.open("POST", "/WriteHere.aspx", true);
  //ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  ajaxObj.send(datURL);
  //ajaxObj.send(encodeURIComponent(datURL));
}

ASPX Code-Behind (VB.net)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  Request.InputStream.Position = 0
  Dim strm = Request.InputStream
  Dim n = CInt(strm.Length)
  Dim arrStrm() As Byte
  ReDim arrStrm(n)

  Dim strmRd = strm.Read(arrStrm, 0, n)

  IO.File.WriteAllBytes("/Foldy/Filey.pdf", arrStrm)

End Sub

Troubleshooting

I’ve spent the past 3 days trying to solve this problem. My troubleshooting has included – but has not been limited to – the following:

  1. Using different JS permutations of FileReader().readAsDataURL()
  2. Using different JS permutations of FileReader().readAsBinaryString()
  3. Using different JS permutations of FileReader().readAsArrayBuffer()
  4. Using different JS permutations of enctype=multipart/form-data
  5. Using different JS permutations of enctype=application/x-www-form-urlencoded
  6. Using different JS permutations of enctype=application/pdf; charset=x-user-defined-binary
  7. Using different JS permutations of enctype=encodeURIComponent
  8. Using different VB permutations of Request.InputStream.Position
  9. Using different VB permutations of Request.InputStream.Read()
  10. Using different VB permutations of Request.InputStream.ReadASync()
  11. Scouring the web for help (especially StackOverflow.com)
  12. Glancing into technology manuals (eg, The Complete Reference to IIS 6)

Request

May you please help me get my HTML-to-ASPX file upload functionality to work for uploaded PDFs?

Thank You

Im just now trying to learn Javascript any way we can work together

New contributor

CanineThaGoat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật