파일 업로드(VB)Uploading Files (VB)
Scott Mitchellby Scott Mitchell
샘플 앱 다운로드 또는 PDF 다운로드Download Sample App or Download PDF
사용자가 파일 시스템 또는 데이터베이스에 저장 될 수 있는 웹 사이트에 사용자가 Word 또는 PDF 문서와 같은 이진 파일을 업로드할 수 있도록 하는 방법에 대해 알아봅니다.Learn how to allow users to upload binary files (such as Word or PDF documents) to your Web site where they may be stored in either the server's file system or the database.
소개Introduction
지금까지 검토 한 모든 자습서는 텍스트 데이터를 사용 하 여 독점적으로 작업 했습니다.All of the tutorials we ve examined so far have worked exclusively with text data. 그러나 많은 응용 프로그램에는 텍스트와 이진 데이터를 모두 캡처하는 데이터 모델이 있습니다.However, many applications have data models that capture both text and binary data. 온라인에 연결 된 사이트를 사용 하면 사용자가 그림을 업로드 하 여 프로필에 연결할 수 있습니다.An online dating site might allow users to upload a picture to associate with their profile. 채용 웹 사이트에서 사용자가 Microsoft Word 또는 PDF 문서로 이력서를 업로드할 수 있습니다.A recruiting website might let users upload their resume as a Microsoft Word or PDF document.
이진 데이터를 사용 하면 새로운 챌린지 집합이 추가 됩니다.Working with binary data adds a new set of challenges. 응용 프로그램에서 이진 데이터를 저장 하는 방법을 결정 해야 합니다.We must decide how the binary data is stored in the application. 사용자가 컴퓨터에서 파일을 업로드할 수 있도록 새 레코드를 삽입 하는 데 사용 되는 인터페이스를 업데이트 해야 하며, 레코드의 연결 된 이진 데이터를 다운로드 하는 방법을 표시 하거나 제공 하기 위해 추가 단계를 수행 해야 합니다.The interface used for inserting new records has to be updated to allow the user to upload a file from their computer and extra steps must be taken to display or provide a means for downloading a record s associated binary data. 이 자습서 및 다음 세 가지는 이러한 문제를 장애물 하는 방법을 살펴보겠습니다.In this tutorial and the next three we'll explore how to hurdle these challenges. 이 자습서의 끝 부분에서는 사진 및 PDF 브로슈어를 각 범주와 연결 하는 완전 한 기능을 갖춘 응용 프로그램을 빌드 했습니다.At the end of these tutorials we'll have built a fully functional application that associates a picture and PDF brochure with each category. 이 특정 자습서에서는 이진 데이터를 저장 하는 다양 한 기술을 살펴보고 사용자가 자신의 컴퓨터에서 파일을 업로드 하 고 웹 서버 s 파일 시스템에 저장 하도록 설정 하는 방법을 살펴봅니다.In this particular tutorial we'll look at different techniques for storing binary data and explore how to enable users to upload a file from their computer and have it saved on the web server s file system.
Note
응용 프로그램 데이터 모델의 일부인 이진 데이터는 BLOB(Binary Large OBject)의 머리글자어 라고도 합니다.Binary data that is part of an application s data model is sometimes referred to as a BLOB, an acronym for Binary Large OBject. 이러한 자습서에서는 BLOB 이라는 용어는 동의어 이지만 용어 이진 데이터를 사용 하도록 선택 했습니다.In these tutorials I have chosen to use the terminology binary data, although the term BLOB is synonymous.
1 단계: 이진 데이터 웹 페이지 작업 만들기Step 1: Creating the Working with Binary Data Web Pages
이진 데이터에 대 한 지원 추가와 관련 된 문제를 살펴보기 전에 먼저이 자습서와 다음 3 개에 필요한 웹 사이트 프로젝트에 ASP.NET 페이지를 만들어 보겠습니다.Before we begin to explore the challenges associated with adding support for binary data, let s first take a moment to create the ASP.NET pages in our website project that we'll need for this tutorial and the next three. BinaryData
이라는 새 폴더를 추가 하 여 시작 합니다.Start by adding a new folder named BinaryData
. 그런 다음, 다음 ASP.NET 페이지를 해당 폴더에 추가 하 여 각 페이지를 Site.master
마스터 페이지에 연결 합니다.Next, add the following ASP.NET pages to that folder, making sure to associate each page with the Site.master
master page:
Default.aspx
FileUpload.aspx
DisplayOrDownloadData.aspx
UploadInDetailsView.aspx
UpdatingAndDeleting.aspx
그림 1: 이진 데이터 관련 자습서에 대 한 ASP.NET 페이지 추가Figure 1: Add the ASP.NET Pages for the Binary Data-Related Tutorials
다른 폴더와 마찬가지로 BinaryData
폴더의 Default.aspx
에는 해당 섹션의 자습서가 나열 됩니다.Like in the other folders, Default.aspx
in the BinaryData
folder will list the tutorials in its section. SectionLevelTutorialListing.ascx
사용자 정의 컨트롤은이 기능을 제공 합니다.Recall that the SectionLevelTutorialListing.ascx
User Control provides this functionality. 따라서이 사용자 정의 컨트롤을 솔루션 탐색기에서 페이지 디자인 뷰로 끌어 Default.aspx
에 추가 합니다.Therefore, add this User Control to Default.aspx
by dragging it from the Solution Explorer onto the page s Design view.
SectionLevelTutorialListing 사용자 정의 컨트롤을 Default.aspx에 추가
그림 2: Default.aspx
에 SectionLevelTutorialListing.ascx
사용자 정의 컨트롤 추가 (전체 크기 이미지를 보려면 클릭)Figure 2: Add the SectionLevelTutorialListing.ascx
User Control to Default.aspx
(Click to view full-size image)
마지막으로, 이러한 페이지를 Web.sitemap
파일에 항목으로 추가 합니다.Lastly, add these pages as entries to the Web.sitemap
file. 특히 GridView <siteMapNode>
을 향상 한 후 다음 태그를 추가 합니다.Specifically, add the following markup after the Enhancing the GridView <siteMapNode>
:
<siteMapNode
title="Working with Binary Data"
url="~/BinaryData/Default.aspx"
description="Extend the data model to include collecting binary data.">
<siteMapNode
title="Uploading Files"
url="~/BinaryData/FileUpload.aspx"
description="Examine the different ways to store binary data on the
web server and see how to accept uploaded files from users
with the FileUpload control." />
<siteMapNode
title="Display or Download Binary Data"
url="~/BinaryData/DisplayOrDownloadData.aspx"
description="Let users view or download the captured binary data." />
<siteMapNode
title="Adding New Binary Data"
url="~/BinaryData/UploadInDetailsView.aspx"
description="Learn how to augment the inserting interface to
include a FileUpload control." />
<siteMapNode
title="Updating and Deleting Existing Binary Data"
url="~/BinaryData/UpdatingAndDeleting.aspx"
description="Learn how to update and delete existing binary data." />
</siteMapNode>
Web.sitemap
업데이트 한 후 브라우저를 통해 자습서 웹 사이트를 잠시 기다려 주십시오.After updating Web.sitemap
, take a moment to view the tutorials website through a browser. 이제 왼쪽의 메뉴에는 이진 데이터 작업 자습서에 대 한 항목이 포함 되어 있습니다.The menu on the left now includes items for the Working with Binary Data tutorials.
그림 3: 이제 사이트 맵에 이진 데이터 사용 자습서에 대 한 항목이 포함 되어 있습니다.Figure 3: The Site Map Now Includes Entries for the Working with Binary Data Tutorials
2 단계: 이진 데이터를 저장할 위치 결정Step 2: Deciding Where to Store the Binary Data
응용 프로그램 데이터 모델과 연결 된 이진 데이터는 웹 서버 파일 시스템에서 데이터베이스에 저장 된 파일에 대 한 참조를 사용 하 여 두 위치 중 하나에 저장 될 수 있습니다. 또는 데이터베이스 자체 내에서 직접 (그림 4 참조).Binary data that is associated with the application s data model can be stored in one of two places: on the web server s file system with a reference to the file stored in the database; or directly within the database itself (see Figure 4). 각 접근 방식에는 고유한 장점 및 단점 집합이 있으며,이에 대 한 자세한 논의는 유용 합니다.Each approach has its own set of pros and cons and merits a more detailed discussion.
이진 데이터를 파일 시스템에 저장 하거나 데이터베이스에 직접 저장할 수
그림 4: 이진 데이터를 파일 시스템에 저장 하거나 데이터베이스에 직접 저장할 수 있습니다 (전체 크기 이미지를 보려면 클릭).Figure 4: Binary Data Can Be Stored On the File System or Directly in the Database (Click to view full-size image)
Northwind 데이터베이스를 확장 하 여 각 제품에 그림을 연결 한다고 가정 합니다.Imagine that we wanted to extend the Northwind database to associate a picture with each product. 한 가지 옵션은 이러한 이미지 파일을 웹 서버의 파일 시스템에 저장 하 고 Products
테이블에 경로를 기록 하는 것입니다.One option would be to store these image files on the web server s file system and record the path in the Products
table. 이 방법을 사용 하는 경우 varchar(200)
형식의 Products
테이블에 ImagePath
열을 추가 합니다.With this approach, we d add an ImagePath
column to the Products
table of type varchar(200)
, perhaps. 사용자가 Chai에 대 한 그림을 업로드 한 경우 해당 그림은 웹 서버의 파일 ~/Images/Tea.jpg
시스템에 저장 될 수 있습니다. 여기서 ~
는 응용 프로그램의 실제 경로를 나타냅니다.When a user uploaded a picture for Chai, that picture might be stored on the web server s file system at ~/Images/Tea.jpg
, where ~
represents the application s physical path. 즉, 웹 사이트가 실제 경로 C:\Websites\Northwind\
를 기반으로 하는 경우 ~/Images/Tea.jpg
C:\Websites\Northwind\Images\Tea.jpg
와 동일 합니다.That is, if the web site is rooted at the physical path C:\Websites\Northwind\
, ~/Images/Tea.jpg
would be equivalent to C:\Websites\Northwind\Images\Tea.jpg
. 이미지 파일을 업로드 한 후에는 해당 ImagePath
열이 새 이미지의 경로를 참조 하도록 Products
테이블에서 Chai 레코드를 업데이트 합니다.After uploading the image file, we d update the Chai record in the Products
table so that its ImagePath
column referenced the path of the new image. 모든 제품 이미지가 응용 프로그램의 Images
폴더에 배치 되도록 결정 한 경우 ~/Images/Tea.jpg
또는 Tea.jpg
를 사용할 수 있습니다.We could use ~/Images/Tea.jpg
or just Tea.jpg
if we decided that all product images would be placed in the application s Images
folder.
이진 데이터를 파일 시스템에 저장 하는 경우의 주요 이점은 다음과 같습니다.The main advantages of storing the binary data on the file system are:
- 구현 용이성 , 데이터베이스에 직접 저장 된 이진 데이터를 저장 하 고 검색 하는 것은 파일 시스템을 통해 데이터로 작업 하는 경우 보다 더 많은 코드가 포함 됩니다.Ease of implementation as we'll see shortly, storing and retrieving binary data stored directly within the database involves a bit more code than when working with data through the file system. 또한 사용자가 이진 데이터를 보거나 다운로드 하려면 해당 데이터에 대 한 URL을 제공 해야 합니다.Additionally, in order for a user to view or download binary data they must be presented with a URL to that data. 데이터가 웹 서버의 파일 시스템에 있는 경우 URL은 간단 합니다.If the data resides on the web server s file system, the URL is straightforward. 그러나 데이터가 데이터베이스에 저장 되어 있는 경우에는 데이터베이스에서 데이터를 검색 하 고 반환 하는 웹 페이지를 만들어야 합니다.If the data is stored in the database, however, a web page needs to be created that will retrieve and return the data from the database.
- 이진 데이터에 대 한 광범위 한 액세스 데이터베이스에서 데이터를 끌어올 수 없는 다른 서비스 또는 응용 프로그램에서 이진 데이터에 액세스할 수 있어야 합니다.Wider access to the binary data the binary data may need to be accessible to other services or applications, ones that cannot pull the data from the database. 예를 들어, 각 제품과 연결 된 이미지를 FTP를 통해 사용자가 사용할 수 있도록 해야 할 수도 있습니다 .이 경우 파일 시스템에 이진 데이터를 저장 하려고 합니다.For example, the images associated with each product might also need to be available to users through FTP, in which case we d want to store the binary data on the file system.
- 성능 이진 데이터가 파일 시스템에 저장 된 경우 데이터베이스 서버와 웹 서버 간의 수요 및 네트워크 정체는 이진 데이터가 데이터베이스 내에 직접 저장 된 경우 보다 낮습니다.Performance if the binary data is stored on the file system, the demand and network congestion between the database server and web server will be less than if the binary data is stored directly within the database.
이진 데이터를 파일 시스템에 저장 하는 경우의 주요 단점은 데이터베이스에서 데이터를 분리는 것입니다.The main disadvantage of storing binary data on the file system is that it decouples the data from the database. Products
테이블에서 레코드를 삭제 하면 웹 서버의 파일 시스템에 있는 관련 파일이 자동으로 삭제 되지 않습니다.If a record is deleted from the Products
table, the associated file on the web server s file system is not automatically deleted. 파일을 삭제 하려면 추가 코드를 작성 해야 합니다. 그렇지 않으면 파일 시스템은 사용 하지 않는 분리 된 파일로 복잡해 집니다.We must write extra code to delete the file or the file system will become cluttered with unused, orphaned files. 또한 데이터베이스를 백업할 때에는 연결 된 이진 데이터를 파일 시스템에도 백업 해야 합니다.Furthermore, when backing up the database, we must make sure to make backups of the associated binary data on the file system, as well. 다른 사이트 또는 서버로 데이터베이스를 이동 하면 비슷한 문제가 발생 합니다.Moving the database to another site or server poses similar challenges.
또는 varbinary
형식의 열을 만들어 Microsoft SQL Server 2005 데이터베이스에 이진 데이터를 직접 저장할 수 있습니다.Alternatively, binary data can be stored directly in a Microsoft SQL Server 2005 database by creating a column of type varbinary
. 다른 가변 길이 데이터 형식과 마찬가지로이 열에 보유할 수 있는 이진 데이터의 최대 길이를 지정할 수 있습니다.Like with other variable length data types, you can specify a maximum length of the binary data that can be held in this column. 예를 들어 최대 5000 바이트를 예약 하려면 varbinary(5000)
을 사용 합니다. varbinary(MAX)
최대 저장소 크기 (약 2gb)를 허용 합니다.For example, to reserve at most 5,000 bytes use varbinary(5000)
; varbinary(MAX)
allows for the maximum storage size, about 2 GB.
이진 데이터를 데이터베이스에 직접 저장 하는 경우의 주요 이점은 이진 데이터와 데이터베이스 레코드를 긴밀 하 게 결합 하는 것입니다.The main advantage of storing binary data directly in the database is the tight coupling between the binary data and the database record. 이렇게 하면 데이터베이스 관리 작업 (예: 백업 또는 데이터베이스를 다른 사이트 또는 서버로 이동)이 매우 간단해 집니다.This greatly simplifies database administration tasks, like backups or moving the database to a different site or server. 또한 레코드를 삭제 하면 해당 하는 이진 데이터가 자동으로 삭제 됩니다.Also, deleting a record automatically deletes the corresponding binary data. 또한 데이터베이스에 이진 데이터를 저장 하면 더 미묘한 이점이 있습니다.There are also more subtle benefits of storing the binary data in the database. 자세히 토론 하려면 ASP.NET 2.0을 사용 하 여 데이터베이스에 직접 이진 파일 저장 을 참조 하세요.See Storing Binary Files Directly in the Database Using ASP.NET 2.0 for a more in-depth discussion.
Note
Microsoft SQL Server 2000 이전 버전에서 varbinary
데이터 형식의 최대 제한은 8000 바이트입니다.In Microsoft SQL Server 2000 and earlier versions, the varbinary
data type had a maximum limit of 8,000 bytes. 최대 2gb의 이진 데이터를 저장 하려면 image
데이터 형식을 대신 사용 해야 합니다.To store up to 2 GB of binary data the image
data type needs to be used instead. 그러나 SQL Server 2005에 MAX
추가 되어 image
데이터 형식은 더 이상 사용 되지 않습니다.With the addition of MAX
in SQL Server 2005, however, the image
data type has been deprecated. 이전 버전과의 호환성을 위해 계속 지원 되지만, image
데이터 형식이 이후 버전의 SQL Server에서 제거 될 것 이라고 발표 했습니다.It s still supported for backwards compatibility, but Microsoft has announced that the image
data type will be removed in a future version of SQL Server.
이전 데이터 모델로 작업 하는 경우 image
데이터 형식이 표시 될 수 있습니다.If you are working with an older data model you may see the image
data type. Northwind 데이터베이스 s Categories
테이블에는 범주에 대 한 이미지 파일의 이진 데이터를 저장 하는 데 사용할 수 있는 Picture
열이 있습니다.The Northwind database s Categories
table has a Picture
column that can be used to store the binary data of an image file for the category. Northwind 데이터베이스의 루트는 Microsoft Access와 이전 버전의 SQL Server 이므로이 열은 image
유형입니다.Since the Northwind database has its roots in Microsoft Access and earlier versions of SQL Server, this column is of type image
.
이 자습서 및 다음 세 가지 방법에서는 두 가지 방법을 모두 사용 합니다.For this tutorial and the next three, we'll use both approaches. Categories
테이블에는 범주에 대 한 이미지의 이진 내용을 저장 하기 위한 Picture
열이 이미 있습니다.The Categories
table already has a Picture
column for storing the binary content of an image for the category. BrochurePath
추가 열을 추가 하 여 인쇄 품질, 범주에 대 한 세련 된 개요를 제공 하는 데 사용할 수 있는 웹 서버 파일 시스템에 PDF 경로를 저장 합니다.We'll add an additional column, BrochurePath
, to store a path to a PDF on the web server s file system that can be used to provide a print-quality, polished overview of the category.
3 단계:Categories
테이블에BrochurePath
열 추가Step 3: Adding theBrochurePath
Column to theCategories
Table
현재 Categories 테이블에는 CategoryID
, CategoryName
, Description
및 Picture
의 4 개 열만 있습니다.Currently the Categories table has only four columns: CategoryID
, CategoryName
, Description
, and Picture
. 이러한 필드 외에도 범주 브로슈어 (있는 경우)를 가리키는 새 필드를 추가 해야 합니다.In addition to these fields, we need to add a new one that will point to the category s brochure (if one exists). 이 열을 추가 하려면 서버 탐색기로 이동 하 여 테이블로 드릴 다운 하 고 Categories
테이블을 마우스 오른쪽 단추로 클릭 한 다음 테이블 정의 열기를 선택 합니다 (그림 5 참조).To add this column, go to the Server Explorer, drill down into the Tables, right-click on the Categories
table and choose Open Table Definition (see Figure 5). 서버 탐색기 표시 되지 않으면 보기 메뉴에서 서버 탐색기 옵션을 선택 하거나 Ctrl + Alt + S를 누르면 됩니다.If you do not see the Server Explorer, bring it up by selecting the Server Explorer option from the View menu, or hit Ctrl+Alt+S.
BrochurePath
라는 Categories
테이블에 새 varchar(200)
열을 추가 하 고 NULL
을 허용 하 고 저장 아이콘을 클릭 하거나 Ctrl + S를 누릅니다.Add a new varchar(200)
column to the Categories
table that is named BrochurePath
and allows NULL
s and click the Save icon (or hit Ctrl+S).
BrochurePath 열을 Categories 테이블에 추가
그림 5: Categories
테이블에 BrochurePath
열 추가 (전체 크기 이미지를 보려면 클릭)Figure 5: Add a BrochurePath
Column to the Categories
Table (Click to view full-size image)
4 단계:Picture
및BrochurePath
열을 사용 하도록 아키텍처 업데이트Step 4: Updating the Architecture to Use thePicture
andBrochurePath
Columns
DAL (데이터 액세스 계층)의 CategoriesDataTable
에는 현재 CategoryID
, CategoryName
, Description
및 NumberOfProducts
정의 된 4 개의 DataColumn
정의 되어 있습니다.The CategoriesDataTable
in the Data Access Layer (DAL) currently has four DataColumn
s defined: CategoryID
, CategoryName
, Description
, and NumberOfProducts
. 데이터 액세스 계층 만들기 자습서에서 원래이 DataTable을 디자인할 때 CategoriesDataTable
에는 처음 3 개의 열만 있습니다. NumberOfProducts
열은 세부 정보 DataList 자습서를 사용 하 여 마스터 레코드의 글머리 기호 목록을 사용 하 여 마스터/세부 정보에 추가 되었습니다.When we originally designed this DataTable in the Creating a Data Access Layer tutorial, the CategoriesDataTable
only had the first three columns; the NumberOfProducts
column was added in the Master/Detail Using a Bulleted List of Master Records with a Details DataList tutorial.
데이터 액세스 계층 만들기에 설명 된 대로 형식화 된 데이터 집합의 datatable는 비즈니스 개체를 구성 합니다.As discussed in Creating a Data Access Layer, the DataTables in the Typed DataSet make up the business objects. Tableadapter는 데이터베이스와 통신 하 고 비즈니스 개체를 쿼리 결과로 채우는 일을 담당 합니다.The TableAdapters are responsible for communicating with the database and populating the business objects with the query results. CategoriesDataTable
는 다음과 같은 세 가지 데이터 검색 방법이 있는 CategoriesTableAdapter
채워집니다.The CategoriesDataTable
is populated by the CategoriesTableAdapter
, which has three data retrieval methods:
GetCategories()
TableAdapter 주 쿼리를 실행 하 고Categories
테이블의 모든 레코드에 대 한CategoryID
,CategoryName
및Description
필드를 반환 합니다.GetCategories()
executes the TableAdapter s main query and returns theCategoryID
,CategoryName
, andDescription
fields of all records in theCategories
table. 기본 쿼리는 자동 생성Insert
및Update
메서드에서 사용 됩니다.The main query is what is used by the auto-generatedInsert
andUpdate
methods.GetCategoryByCategoryID(categoryID)
은CategoryID
가 categoryID와 동일한 범주의CategoryID
,CategoryName
및Description
필드를 반환 합니다.GetCategoryByCategoryID(categoryID)
returns theCategoryID
,CategoryName
, andDescription
fields of the category whoseCategoryID
equals categoryID.GetCategoriesAndNumberOfProducts()
-Categories
테이블의 모든 레코드에 대 한CategoryID
,CategoryName
및Description
필드를 반환 합니다.GetCategoriesAndNumberOfProducts()
- returns theCategoryID
,CategoryName
, andDescription
fields for all records in theCategories
table. 또한는 하위 쿼리를 사용 하 여 각 범주와 관련 된 제품 수를 반환 합니다.Also uses a subquery to return the number of products associated with each category.
이러한 쿼리는 Categories
테이블 s Picture
또는 BrochurePath
열을 반환 하지 않습니다. 및는 이러한 필드에 대해 DataColumn
CategoriesDataTable
제공 하지 않습니다.Notice that none of these queries return the Categories
table s Picture
or BrochurePath
columns; nor does the CategoriesDataTable
provide DataColumn
s for these fields. 그림 및 BrochurePath
속성을 사용 하려면 먼저 CategoriesDataTable
에 추가한 다음 이러한 열을 반환 하도록 CategoriesTableAdapter
클래스를 업데이트 해야 합니다.In order to work with the Picture and BrochurePath
properties, we need to first add them to the CategoriesDataTable
and then update the CategoriesTableAdapter
class to return these columns.
Picture
및BrochurePath``DataColumn
추가Adding thePicture
andBrochurePath``DataColumn
s
이러한 두 열을 CategoriesDataTable
에 추가 하 여 시작 합니다.Start by adding these two columns to the CategoriesDataTable
. CategoriesDataTable
s 헤더를 마우스 오른쪽 단추로 클릭 하 고 상황에 맞는 메뉴에서 추가를 선택한 다음 열 옵션을 선택 합니다.Right-click on the CategoriesDataTable
s header, select Add from the context menu and then choose the Column option. 이렇게 하면 Column1
라는 DataTable에 새 DataColumn
만들어집니다.This will create a new DataColumn
in the DataTable named Column1
. 이 열의 이름을 Picture
로 바꿉니다.Rename this column to Picture
. 속성 창에서 DataColumn
s DataType
속성을 System.Byte[]
로 설정 합니다 .이 속성은 드롭다운 목록에서 옵션이 아닙니다. 입력 해야 합니다.From the Properties window, set the DataColumn
s DataType
property to System.Byte[]
(this is not an option in the drop-down list; you need to type it in).
데이터 형식이 system.string [] 인 DataColumn 이름이 지정 된 그림을 만듭니다
그림 6: DataType
System.Byte[]
인 Picture
라는 DataColumn
만들기 (전체 크기 이미지를 보려면 클릭)Figure 6: Create a DataColumn
Named Picture
whose DataType
is System.Byte[]
(Click to view full-size image)
DataTable에 다른 DataColumn
를 추가 하 고 기본 DataType
값 (System.String
)을 사용 하 여 BrochurePath
이름을 지정 합니다.Add another DataColumn
to the DataTable, naming it BrochurePath
using the default DataType
value (System.String
).
TableAdapter의Picture
및BrochurePath
값 반환Returning thePicture
andBrochurePath
Values from the TableAdapter
이러한 두 DataColumn
s CategoriesDataTable
에 추가 되 면 CategoriesTableAdapter
를 업데이트할 준비가 된 것입니다.With these two DataColumn
s added to the CategoriesDataTable
, we re ready to update the CategoriesTableAdapter
. 주 TableAdapter 쿼리에서 이러한 열 값을 모두 반환 했을 수 있지만이는 GetCategories()
메서드가 호출 될 때마다 이진 데이터를 다시 가져옵니다.We could have both of these column values returned in the main TableAdapter query, but this would bring back the binary data every time the GetCategories()
method was invoked. 대신, BrochurePath
다시 가져와서 특정 범주 Picture
열을 반환 하는 추가 데이터 검색 메서드를 만들도록 주 TableAdapter 쿼리를 업데이트 해 보겠습니다.Instead, let s update the main TableAdapter query to bring back BrochurePath
and create an additional data retrieval method that returns a particular category s Picture
column.
주 TableAdapter 쿼리를 업데이트 하려면 CategoriesTableAdapter
s 헤더를 마우스 오른쪽 단추로 클릭 하 고 상황에 맞는 메뉴에서 구성 옵션을 선택 합니다.To update the main TableAdapter query, right-click on the CategoriesTableAdapter
s header and choose the Configure option from the context menu. 이렇게 하면 몇 가지 이전 자습서에서 살펴본 테이블 어댑터 구성 마법사가 나타납니다.This brings up the Table Adapter Configuration Wizard, which we ve seen in a number of past tutorials. BrochurePath
를 다시 가져오려면 쿼리를 업데이트 하 고 [마침]을 클릭 하십시오.Update the query to bring back the BrochurePath
and click Finish.
그림 7: BrochurePath
을 반환 하도록 SELECT
문에서 열 목록 업데이트 (전체 크기 이미지를 보려면 클릭)Figure 7: Update the Column List in the SELECT
Statement to Also Return BrochurePath
(Click to view full-size image)
TableAdapter에 대해 임시 SQL 문을 사용 하는 경우 주 쿼리에서 열 목록을 업데이트 하면 TableAdapter의 모든 SELECT
쿼리 메서드에 대 한 열 목록이 업데이트 됩니다.When using ad-hoc SQL statements for the TableAdapter, updating the column list in the main query updates the column list for all of the SELECT
query methods in the TableAdapter. 즉, GetCategoryByCategoryID(categoryID)
메서드가 BrochurePath
열을 반환 하도록 업데이트 되었으므로 의도 한 것이 될 수 있습니다.That means the GetCategoryByCategoryID(categoryID)
method has been updated to return the BrochurePath
column, which might be what we intended. 그러나 GetCategoriesAndNumberOfProducts()
메서드에서 열 목록을 업데이트 하 여 각 범주에 대 한 제품 수를 반환 하는 하위 쿼리를 제거 합니다.However, it also updated the column list in the GetCategoriesAndNumberOfProducts()
method, removing the subquery that returns the number of products for each category! 따라서이 메서드 SELECT
쿼리를 업데이트 해야 합니다.Therefore, we need to update this method s SELECT
query. GetCategoriesAndNumberOfProducts()
메서드를 마우스 오른쪽 단추로 클릭 하 고 구성을 선택한 다음 SELECT
쿼리를 원래 값으로 되돌립니다.Right-click on the GetCategoriesAndNumberOfProducts()
method, choose Configure, and revert the SELECT
query back to its original value:
SELECT CategoryID, CategoryName, Description,
(SELECT COUNT(*)
FROM Products p
WHERE p.CategoryID = c.CategoryID)
as NumberOfProducts
FROM Categories c
다음으로, 특정 범주 Picture
열 값을 반환 하는 새 TableAdapter 메서드를 만듭니다.Next, create a new TableAdapter method that returns a particular category s Picture
column value. CategoriesTableAdapter
s 헤더를 마우스 오른쪽 단추로 클릭 하 고 쿼리 추가 옵션을 선택 하 여 TableAdapter 쿼리 구성 마법사를 시작 합니다.Right-click on the CategoriesTableAdapter
s header and choose the Add Query option to launch the TableAdapter Query Configuration Wizard. 이 마법사의 첫 번째 단계에서는 임시 SQL 문, 새 저장 프로시저 또는 기존 항목을 사용 하 여 데이터를 쿼리해야 하는지 묻는 메시지를 표시 합니다.The first step of this wizard asks us if we want to query data using an ad-hoc SQL statement, a new stored procedure, or an existing one. SQL 문 사용을 선택 하 고 다음을 클릭 합니다.Select Use SQL statements and click Next. 행을 반환할 것 이므로 두 번째 단계에서 행을 반환 하는 옵션을 선택 합니다.Since we will be returning a row, choose the SELECT which returns rows option from the second step.
그림 8: SQL 문 사용 옵션 선택 (전체 크기 이미지를 보려면 클릭)Figure 8: Select the Use SQL statements Option (Click to view full-size image)
그림 9: 쿼리에서 Categories 테이블의 레코드를 반환 하기 때문에 행을 반환 하는 선택 (전체 크기 이미지를 보려면 클릭)을 선택 합니다.Figure 9: Since the Query Will Return a Record from the Categories Table, Choose SELECT which returns rows (Click to view full-size image)
세 번째 단계에서 다음 SQL 쿼리를 입력 하 고 다음을 클릭 합니다.In the third step, enter the following SQL query and click Next:
SELECT CategoryID, CategoryName, Description, BrochurePath, Picture
FROM Categories
WHERE CategoryID = @CategoryID
마지막 단계는 새 메서드의 이름을 선택 하는 것입니다.The last step is to choose the name for the new method. FillCategoryWithBinaryDataByCategoryID
및 GetCategoryWithBinaryDataByCategoryID
를 사용 하 여 DataTable을 채우고 DataTable 패턴을 반환 합니다.Use FillCategoryWithBinaryDataByCategoryID
and GetCategoryWithBinaryDataByCategoryID
for the Fill a DataTable and Return a DataTable patterns, respectively. 마침을 클릭하여 마법사를 완료합니다.Click Finish to complete the wizard.
그림 10: TableAdapter의 메서드 이름 선택 (전체 크기 이미지를 보려면 클릭)Figure 10: Choose the Names for the TableAdapter s Methods (Click to view full-size image)
Note
테이블 어댑터 쿼리 구성 마법사를 완료 한 후 새 명령 텍스트에서 주 쿼리의 스키마와 다른 스키마가 있는 데이터를 반환 한다는 것을 알리는 대화 상자가 표시 될 수 있습니다.After completing the Table Adapter Query Configuration Wizard you may see a dialog box informing you that the new command text returns data with schema different from the schema of the main query. 간단히 말해서, 마법사는 TableAdapter의 주 쿼리 GetCategories()
방금 만든 스키마와 다른 스키마를 반환 한다는 것을 주목 합니다.In short, the wizard is noting that the TableAdapter s main query GetCategories()
returns a different schema than the one we just created. 하지만이 메시지는 무시 해도 됩니다.But this is what we want, so you can disregard this message.
또한 임시 SQL 문을 사용 하 고 마법사를 사용 하 여 나중에 TableAdapter 주 쿼리를 변경 하는 경우 주 쿼리의 해당 열만 포함 하도록 GetCategoryWithBinaryDataByCategoryID
메서드 SELECT
문 열 목록을 수정 합니다. 즉, 쿼리에서 Picture
열을 제거 합니다.)를 고려해 야 합니다.Also, keep in mind that if you are using ad-hoc SQL statements and use the wizard to change the TableAdapter s main query at some later point in time, it will modify the GetCategoryWithBinaryDataByCategoryID
method s SELECT
statement s column list to include just those columns from the main query (that is, it will remove the Picture
column from the query). Picture
열을 반환 하도록 열 목록을 수동으로 업데이트 해야 합니다 .이 단계에서는 이전에 GetCategoriesAndNumberOfProducts()
메서드를 사용 했을 때와 비슷합니다.You will have to manually update the column list to return the Picture
column, similar to what we did with the GetCategoriesAndNumberOfProducts()
method earlier in this step.
CategoriesDataTable
에 두 개의 DataColumn
s를 추가 하 고 GetCategoryWithBinaryDataByCategoryID
메서드를 CategoriesTableAdapter
에 추가한 후에는 형식화 된 데이터 집합 디자이너의 이러한 클래스가 그림 11의 스크린샷 처럼 보입니다.After adding the two DataColumn
s to the CategoriesDataTable
and the GetCategoryWithBinaryDataByCategoryID
method to the CategoriesTableAdapter
, these classes in the Typed DataSet Designer should look like the screenshot in Figure 11.
그림 11: 새 열과 메서드를 포함 하는 데이터 집합 디자이너Figure 11: The DataSet Designer Includes the New Columns and Method
BLL (비즈니스 논리 계층) 업데이트Updating the Business Logic Layer (BLL)
DAL이 업데이트 되 면 새 CategoriesTableAdapter
메서드에 대 한 메서드를 포함 하도록 BLL (비즈니스 논리 계층)을 보강 하는 것만 남았습니다.With the DAL updated, all that remains is to augment the Business Logic Layer (BLL) to include a method for the new CategoriesTableAdapter
method. CategoriesBLL
클래스에 다음 메서드를 추가합니다.Add the following method to the CategoriesBLL
class:
<System.ComponentModel.DataObjectMethodAttribute _
(System.ComponentModel.DataObjectMethodType.Select, False)> _
Public Function GetCategoryWithBinaryDataByCategoryID(categoryID As Integer) _
As Northwind.CategoriesDataTable
Return Adapter.GetCategoryWithBinaryDataByCategoryID(categoryID)
End Function
5 단계: 클라이언트에서 웹 서버로 파일 업로드Step 5: Uploading a File From the Client to the Web Server
이진 데이터를 수집 하는 경우이 데이터는 최종 사용자가 제공 하는 경우가 많습니다.When collecting binary data, oftentimes this data is supplied by an end user. 이 정보를 캡처하려면 사용자가 자신의 컴퓨터에서 웹 서버로 파일을 업로드할 수 있어야 합니다.To capture this information, the user needs to be able to upload a file from their computer to the web server. 그런 다음 업로드 된 데이터를 데이터 모델과 통합 해야 합니다 .이 경우 파일을 웹 서버의 파일 시스템에 저장 하 고 데이터베이스의 파일에 경로를 추가 하거나 이진 콘텐츠를 데이터베이스에 직접 쓸 수 있습니다.The uploaded data then needs to be integrated with the data model, which may mean saving the file to the web server s file system and adding a path to the file in the database, or writing the binary contents directly into the database. 이 단계에서는 사용자가 자신의 컴퓨터에서 서버로 파일을 업로드할 수 있도록 허용 하는 방법을 살펴보겠습니다.In this step we'll look at how to allow a user to upload files from their computer to the server. 다음 자습서에서는 업로드 된 파일을 데이터 모델과 통합 하는 데 주의를 기울여야 합니다.In the next tutorial we'll turn our attention to integrating the uploaded file with data model.
ASP.NET 2.0 s new FileUpload 웹 컨트롤 은 사용자가 자신의 컴퓨터에서 웹 서버로 파일을 보낼 수 있는 메커니즘을 제공 합니다.ASP.NET 2.0 s new FileUpload Web control provides a mechanism for users to send a file from their computer to the web server. FileUpload 컨트롤은 type
특성이 file로 설정 된 <input>
요소로 렌더링 합니다. 브라우저는 찾아보기 단추를 사용 하 여 텍스트 상자로 표시 합니다.The FileUpload control renders as an <input>
element whose type
attribute is set to file, which browsers display as a textbox with a Browse button. 찾아보기 단추를 클릭 하면 사용자가 파일을 선택할 수 있는 대화 상자가 나타납니다.Clicking the Browse button brings up a dialog box from which the user can select a file. 양식이 다시 게시 되 면 선택한 파일의 내용이 다시 게시와 함께 전송 됩니다.When the form is posted back, the selected file s contents are sent along with the postback. 서버 쪽에서 업로드 된 파일에 대 한 정보는 FileUpload 컨트롤의 속성을 통해 액세스할 수 있습니다.On the server-side, information about the uploaded file is accessible through the FileUpload control s properties.
파일 업로드를 시연 하려면 BinaryData
폴더에서 FileUpload.aspx
페이지를 열고, 도구 상자에서 FileUpload 컨트롤을 디자이너로 끌고, 컨트롤의 ID
속성을 UploadTest
로 설정 합니다.To demonstrate uploading files, open the FileUpload.aspx
page in the BinaryData
folder, drag a FileUpload control from the Toolbox onto the Designer, and set the control s ID
property to UploadTest
. 그런 다음, 해당 ID
을 설정 하 고 Text
속성을 설정 하 여 선택한 파일을 UploadButton
및 업로드 하는 단추 웹 컨트롤을 추가 합니다.Next, add a Button Web control setting its ID
and Text
properties to UploadButton
and Upload Selected File, respectively. 마지막으로 단추 아래에 Label 웹 컨트롤을 놓고 Text
속성을 지우고 ID
속성을 UploadDetails
로 설정 합니다.Finally, place a Label Web control beneath the Button, clear out its Text
property and set its ID
property to UploadDetails
.
FileUpload 컨트롤을 ASP.NET 페이지에 추가
그림 12: ASP.NET 페이지에 FileUpload 컨트롤 추가 (전체 크기 이미지를 보려면 클릭)Figure 12: Add a FileUpload Control to the ASP.NET Page (Click to view full-size image)
그림 13에서는 브라우저를 통해 볼 때이 페이지를 보여 줍니다.Figure 13 shows this page when viewed through a browser. 찾아보기 단추를 클릭 하면 파일 선택 대화 상자가 표시 되어 사용자가 컴퓨터에서 파일을 선택할 수 있습니다.Note that clicking the Browse button brings up a file selection dialog box, allowing the user to pick a file from their computer. 파일이 선택 되 면 선택한 파일 업로드 단추를 클릭 하면 선택한 파일의 이진 콘텐츠를 웹 서버로 전송 하는 포스트백이 발생 합니다.Once a file has been selected, clicking the Upload Selected File button causes a postback that sends the selected file s binary content to the web server.
그림 13: 사용자는 컴퓨터에서 서버로 업로드할 파일을 선택할 수 있습니다 (전체 크기 이미지를 보려면 클릭).Figure 13: The User Can Select a File to Upload from their Computer to the Server (Click to view full-size image)
다시 게시 하는 경우 업로드 된 파일을 파일 시스템에 저장 하거나, 해당 이진 데이터를 스트림을 통해 직접 작업을 수행할 수 있습니다.On postback, the uploaded file can be saved to the file system or its binary data can be worked with directly through a Stream. 이 예에서는 ~/Brochures
폴더를 만들고 업로드 된 파일을 저장 합니다.For this example, let s create a ~/Brochures
folder and save the uploaded file there. 먼저 Brochures
폴더를 루트 디렉터리의 하위 폴더로 사이트에 추가 합니다.Start by adding the Brochures
folder to the site as a subfolder of the root directory. 다음으로 UploadButton
s Click
이벤트에 대 한 이벤트 처리기를 만들고 다음 코드를 추가 합니다.Next, create an event handler for the UploadButton
s Click
event and add the following code:
Protected Sub UploadButton_Click(sender As Object, e As EventArgs) _
Handles UploadButton.Click
If UploadTest.HasFile = False Then
' No file uploaded!
UploadDetails.Text = "Please first select a file to upload..."
Else
' Display the uploaded file's details
UploadDetails.Text = String.Format( _
"Uploaded file: {0}<br />" & _
"File size (in bytes): {1:N0}<br />" & _
"Content-type: {2}", _
UploadTest.FileName, _
UploadTest.FileBytes.Length, _
UploadTest.PostedFile.ContentType)
' Save the file
Dim filePath As String = _
Server.MapPath("~/Brochures/" & UploadTest.FileName)
UploadTest.SaveAs(filePath)
End If
End Sub
FileUpload 컨트롤은 업로드 된 데이터를 사용 하기 위한 다양 한 속성을 제공 합니다.The FileUpload control provides a variety of properties for working with the uploaded data. 예를 들어 HasFile
속성 은 파일이 사용자에 의해 업로드 되었는지 여부를 나타내며 FileBytes
속성 은 업로드 된 이진 데이터에 대 한 액세스를 바이트 배열로 제공 합니다.For instance, the HasFile
property indicates whether a file was uploaded by the user, while the FileBytes
property provides access to the uploaded binary data as an array of bytes. Click
이벤트 처리기는 파일이 업로드 되었는지 확인 하 여 시작 합니다.The Click
event handler starts by ensuring that a file has been uploaded. 파일이 업로드 된 경우에는 업로드 된 파일의 이름, 크기 (바이트) 및 해당 콘텐츠 형식에 레이블이 표시 됩니다.If a file has been uploaded, the Label shows the name of the uploaded file, its size in bytes, and its content-type.
Note
사용자가 파일을 업로드 하도록 하려면 HasFile
속성을 확인 하 고 False
되는 경우 경고를 표시 하거나 대신 Requiredfieldvalidator 컨트롤 을 사용할 수 있습니다.To ensure that the user uploads a file you can check the HasFile
property and display a warning if it s False
, or you may use the RequiredFieldValidator control instead.
FileUpload s SaveAs(filePath)
는 업로드 된 파일을 지정 된 파일 경로에 저장 합니다.The FileUpload s SaveAs(filePath)
saves the uploaded file to the specified filePath. filePath 는 가상 경로 (/Brochures/SomeFile.pdf
)가 아닌 실제 경로 (C:\Websites\Brochures\SomeFile.pdf
) 여야 합니다.filePath must be a physical path (C:\Websites\Brochures\SomeFile.pdf
) rather than a virtual path (/Brochures/SomeFile.pdf
). Server.MapPath(virtPath)
메서드 는 가상 경로를 사용 하 여 해당 하는 실제 경로를 반환 합니다.The Server.MapPath(virtPath)
method takes a virtual path and returns its corresponding physical path. 여기에서 가상 경로는 ~/Brochures/fileName
됩니다. 여기서 fileName 은 업로드 된 파일의 이름입니다.Here, the virtual path is ~/Brochures/fileName
, where fileName is the name of the uploaded file. 가상 및 실제 경로와 Server.MapPath
사용에 대 한 자세한 내용은 node.js 사용 을 참조 하세요.See Using Server.MapPath for more information on virtual and physical paths and using Server.MapPath
.
Click
이벤트 처리기를 완료 한 후 잠시 브라우저에서 페이지를 테스트 합니다.After completing the Click
event handler, take a moment to test out the page in a browser. 찾아보기 단추를 클릭 하 고 하드 드라이브에서 파일을 선택한 다음 선택한 파일 업로드 단추를 클릭 합니다.Click the Browse button and select a file from your hard drive and then click the Upload Selected File button. 다시 게시 하면 선택한 파일의 내용이 웹 서버로 전송 됩니다. 그러면 해당 파일을 ~/Brochures
폴더에 저장 하기 전에 파일에 대 한 정보가 표시 됩니다.The postback will send the contents of the selected file to the web server, which will then display information about the file before saving it to the ~/Brochures
folder. 파일을 업로드 한 후에 Visual Studio로 돌아가서 솔루션 탐색기에서 새로 고침 단추를 클릭 합니다.After uploading the file, return to Visual Studio and click the Refresh button in the Solution Explorer. 방금 업로드 한 파일이 ~/Hs 폴더에 표시 됩니다.You should see the file you just uploaded in the ~/Brochures folder!
그림 14: EvolutionValley.jpg
파일을 웹 서버에 업로드 했습니다 (전체 크기 이미지를 보려면 클릭).Figure 14: The File EvolutionValley.jpg
Has Been Uploaded to the Web Server (Click to view full-size image)
그림 15: EvolutionValley.jpg
~/Brochures
폴더에 저장 됨Figure 15: EvolutionValley.jpg
Was Saved to the ~/Brochures
Folder
업로드 된 파일을 파일 시스템에 저장 하는 경우의 미묘한Subtleties with Saving Uploaded Files to the File System
웹 서버의 파일 시스템에 업로드 파일을 저장할 때 해결 해야 하는 여러 가지 미묘한 내용이 있습니다.There are several subtleties that must be addressed when saving uploading files to the web server s file system. 먼저 보안 문제가 있습니다.First, there s the issue of security. 파일 시스템에 파일을 저장 하려면 ASP.NET 페이지를 실행 하는 보안 컨텍스트에 쓰기 권한이 있어야 합니다.To save a file to the file system, the security context under which the ASP.NET page is executing must have Write permissions. ASP.NET Development 웹 서버는 현재 사용자 계정의 컨텍스트에서 실행 됩니다.The ASP.NET Development Web Server runs under the context of your current user account. Microsoft s 인터넷 정보 서비스 (IIS)를 웹 서버로 사용 하는 경우 보안 컨텍스트는 IIS 및 해당 구성의 버전에 따라 달라 집니다.If you are using Microsoft s Internet Information Services (IIS) as the web server, the security context depends on the version of IIS and its configuration.
파일을 파일 시스템에 저장 하는 또 다른 문제는 파일의 이름을 지정 하는 것입니다.Another challenge of saving files to the file system revolves around naming the files. 현재 페이지에는 클라이언트 컴퓨터의 파일과 동일한 이름을 사용 하 여 업로드 된 모든 파일이 ~/Brochures
디렉터리에 저장 됩니다.Currently, our page saves all of the uploaded files to the ~/Brochures
directory using the same name as the file on the client s computer. 사용자 A가 Brochure.pdf
이름의 브로슈어를 업로드 하는 경우이 파일은 ~/Brochure/Brochure.pdf
으로 저장 됩니다.If User A uploads a brochure with the name Brochure.pdf
, the file will be saved as ~/Brochure/Brochure.pdf
. 그러나 나중에 사용자 B가 동일한 파일 이름 (Brochure.pdf
)을 가진 다른 브로슈어 파일을 업로드 하는 경우는 어떻게 되나요?But what if sometime later User B uploads a different brochure file that happens to have the same filename (Brochure.pdf
)? 이제 코드를 사용 하 여 user A s 파일은 사용자 B s 업로드로 덮어쓰여집니다.With the code we have now, User A s file will be overwritten with User B s upload.
파일 이름 충돌을 해결 하는 방법에는 여러 가지가 있습니다.There are a number of techniques for resolving file name conflicts. 한 가지 옵션은 이름이 같은 파일이 이미 있는 경우 파일을 업로드 하는 것을 금지 하는 것입니다.One option is to prohibit uploading a file if there already exists one with the same name. 이 방법을 사용 하면 사용자 B가 Brochure.pdf
파일을 업로드 하려고 할 때 시스템은 파일을 저장 하지 않고 대신 사용자 B에 게 파일 이름을 바꾸고 다시 시도 하 라는 메시지를 표시 합니다.With this approach, when User B attempts to upload a file named Brochure.pdf
, the system would not save their file and instead display a message informing User B to rename the file and try again. 또 다른 방법은 고유한 파일 이름을 사용 하 여 파일을 저장 하는 것입니다 .이는 guid (globally unique identifier ) 또는 해당 데이터베이스 레코드의 기본 키 열에 있는 값이 될 수 있습니다 (업로드가 데이터 모델의 특정 행과 연결 된 것으로 가정).Another approach is to save the file using a unique file name, which could be a globally unique identifier (GUID) or the value from the corresponding database record s primary key column(s) (assuming that the upload is associated with a particular row in the data model). 다음 자습서에서는 이러한 옵션에 대해 자세히 설명 합니다.In the next tutorial we'll explore these options in more detail.
매우 많은 양의 이진 데이터와 관련 된 과제Challenges Involved with Very Large Amounts of Binary Data
이러한 자습서에서는 캡처된 이진 데이터의 크기가 적당 하다 고 가정 합니다.These tutorials assume that the binary data captured is modest in size. 몇 메가바이트 이상의 이진 데이터 파일에 대 한 작업에는 이러한 자습서의 범위를 벗어나는 새로운 과제가 도입 됩니다.Working with very large amounts of binary data files that are several megabytes or larger introduces new challenges that are beyond the scope of these tutorials. 예를 들어, ASP.NET는 Web.config
의 <httpRuntime>
요소 를 통해 구성할 수 있지만 기본적으로는 4mb 이상의 업로드를 거부 합니다.For example, by default ASP.NET will reject uploads of more than 4 MB, although this can be configured through the <httpRuntime>
element in Web.config
. IIS는 자체 파일 업로드 크기 제한도 적용 합니다.IIS imposes its own file upload size limitations, too. 자세한 내용은 IIS 업로드 파일 크기 를 참조 하십시오.See IIS Upload File Size for more information. 또한 많은 파일을 업로드 하는 데 걸리는 시간이 기본 110 초를 초과 하면 ASP.NET가 요청을 대기 합니다.Furthermore, the time taken to upload large files might exceed the default 110 seconds ASP.NET will wait for a request. 또한 많은 파일을 사용할 때 발생 하는 메모리 및 성능 문제가 있습니다.There are also memory and performance issues that arise when working with large files.
FileUpload 컨트롤은 대량 파일 업로드에 적합 하지 않습니다.The FileUpload control is impractical for large file uploads. 파일의 콘텐츠를 서버에 게시 하면 최종 사용자가 업로드가 진행 되 고 있는지 확인 하지 않고 patiently 대기 해야 합니다.As the file s contents are being posted to the server, the end user must patiently wait without any confirmation that their upload is progressing. 몇 초 안에 업로드할 수 있는 작은 파일을 처리할 경우에는 문제가 되지 않지만 업로드 하는 데 몇 분이 걸릴 수 있는 큰 파일을 처리할 때 문제가 될 수 있습니다.This is not so much an issue when dealing with smaller files that can be uploaded in a few seconds, but can be an issue when dealing with larger files that may take minutes to upload. 큰 업로드를 처리 하는 데 더 적합 한 다양 한 타사 파일 업로드 컨트롤이 있으며 이러한 공급 업체 대부분은 진행률 표시기와 훨씬 더 세련 된 사용자 환경을 제공 하는 ActiveX 업로드 관리자를 제공 합니다.There are a variety of third-party file upload controls that are better suited for handling large uploads and many of these vendors provide progress indicators and ActiveX upload managers that present a much more polished user experience.
응용 프로그램에서 규모가 많은 파일을 처리 해야 하는 경우 문제를 자세히 조사 하 고 특정 요구 사항에 적합 한 솔루션을 찾아야 합니다.If your application needs to handle large files, you'll need to carefully investigate the challenges and find suitable solutions for your particular needs.
요약Summary
이진 데이터를 캡처해야 하는 응용 프로그램을 빌드하면 많은 과제가 발생 합니다.Building an application that needs to capture binary data introduces a number of challenges. 이 자습서에서는 처음 두 가지를 살펴보았습니다. 이진 데이터를 저장할 위치를 결정 하 고 사용자가 웹 페이지를 통해 이진 콘텐츠를 업로드할 수 있습니다.In this tutorial we explored the first two: deciding where to store the binary data and allowing a user to upload binary content through a web page. 다음 세 가지 자습서를 통해 업로드 된 데이터를 데이터베이스의 레코드와 연결 하는 방법 뿐만 아니라 텍스트 데이터 필드와 함께 이진 데이터를 표시 하는 방법을 확인할 수 있습니다.Over the next three tutorials, we'll see how to associate the uploaded data with a record in the database as well as how to display the binary data alongside its text data fields.
행복 한 프로그래밍Happy Programming!
추가 참고 자료Further Reading
이 자습서에서 설명 하는 항목에 대 한 자세한 내용은 다음 리소스를 참조 하세요.For more information on the topics discussed in this tutorial, refer to the following resources:
- 대량 값 데이터 형식 사용Using Large-Value Data Types
- FileUpload 컨트롤 빠른 시작FileUpload Control QuickStarts
- ASP.NET 2.0 FileUpload Server 컨트롤The ASP.NET 2.0 FileUpload Server Control
- 파일 업로드의 어두운 쪽The Dark Side of File Uploads
저자 정보About the Author
Scott Mitchell(7 개의 ASP/ASP. NET books 및 4GuysFromRolla.com창립자)은 1998부터 Microsoft 웹 기술을 사용 하 여 작업 했습니다.Scott Mitchell, author of seven ASP/ASP.NET books and founder of 4GuysFromRolla.com, has been working with Microsoft Web technologies since 1998. Scott은 독립 컨설턴트, 강사 및 기록기로 작동 합니다.Scott works as an independent consultant, trainer, and writer. 최신 책은 24 시간 이내에 ASP.NET 2.0을 sams teach yourself것입니다.His latest book is Sams Teach Yourself ASP.NET 2.0 in 24 Hours. mitchell@4GuysFromRolla.com에 도달할 수 있습니다 .He can be reached at mitchell@4GuysFromRolla.com. 또는 블로그를 통해 http://ScottOnWriting.NET에서 찾을 수 있습니다.or via his blog, which can be found at http://ScottOnWriting.NET.
특별히 감사 합니다.Special Thanks To
이 자습서 시리즈는 많은 유용한 검토자가 검토 했습니다.This tutorial series was reviewed by many helpful reviewers. 이 자습서에 대 한 리드 검토자는 Teresa Murphy 및 Bernadette Leigh입니다.Lead reviewers for this tutorial were Teresa Murphy and Bernadette Leigh. 예정 된 MSDN 문서를 검토 하는 데 관심이 있나요?Interested in reviewing my upcoming MSDN articles? 그렇다면mitchell@4GuysFromRolla.com에서 줄을 삭제 합니다.If so, drop me a line at mitchell@4GuysFromRolla.com.